Skip to content

Instantly share code, notes, and snippets.

@MajesticPotatoe
Created October 30, 2019 14:46
Show Gist options
  • Save MajesticPotatoe/37cac034e3294a31d8e0d6c7c8ef9f04 to your computer and use it in GitHub Desktop.
Save MajesticPotatoe/37cac034e3294a31d8e0d6c7c8ef9f04 to your computer and use it in GitHub Desktop.
scheduleData = await this.epms
.distinct(
'a.JobNumber',
'a.EstimateNumber',
'a.CustAccount',
'a.CustName',
'a.CSR',
'a.SalesRepCode AS SalesRep',
'a.Estimator',
'a.JobDescription',
'a.JobStatus',
'a.UserDefined1 AS Planner',
'a.UserDefined2 AS Status',
'a.ProofDate AS PromisedDate',
'b.ComponentNumber',
'b.Description',
'd.CostCenterCode',
'e.CostCenterDescription AS PlannedCostcenter',
'g.CostCenterDescription AS ScheduledCostcenter'
)
.select(this.epms.raw(`
a.DueDate AT TIME ZONE 'Eastern Standard Time' AS DueDate,
(f.StartDate + f.StartTime) AT TIME ZONE 'Eastern Standard Time' AS ScheduledStart,
(f.EndDate + f.EndTime) AT TIME ZONE 'Eastern Standard Time' AS ScheduledEnd,
(CASE WHEN b.ComponentType = 'FLEXO' THEN b.DieNumber ELSE c.DieNumber END) AS DieNumber,
(CASE WHEN b.ComponentType = 'FLEXO' THEN ba.UserDefined6 ELSE ca.UserDefined6 END) AS DieStatus,
(CASE WHEN b.ComponentType = 'FLEXO' THEN ba.LocationCode ELSE ca.LocationCode END) AS DieLocation
`))
.from('OrderHeader AS a')
.leftJoin('OrderComponent AS b', 'a.JobNumber', 'b.JobNumber')
.leftJoin('DieInventory AS ba', 'b.DieNumber', 'ba.DieCode')
.leftJoin('OrderProcess AS c', function() {
this
.on('b.JobNumber', 'c.JobNumber')
.on('b.ComponentNumber', 'c.ComponentNumber');
})
.leftJoin('DieInventory AS ca', 'c.DieNumber', 'ca.DieCode')
.leftJoin('Process AS d', 'c.ProcessCode', 'd.ProcessCode')
.leftJoin('CostCenter AS e', 'd.CostCenterCode', 'e.CostCenterCode')
.leftJoin('ProcessSchedule AS f', function() {
this
.on('e.CostCenterCode', 'f.OriginalCostCenter')
.on('b.JobNumber', 'f.JobNumber')
.on('b.ComponentNumber', 'f.ComponentNumber');
})
.leftJoin('CostCenter AS g', 'f.CostCenterCode', 'g.CostCenterCode')
.where(where)
.whereRaw(whereRaw)
.map(async (row) => {
row.ID = `${row.JobNumber}${row.ComponentNumber}${row.CostCenterCode}`;
const query = {
job_number: row.JobNumber,
component_number: row.ComponentNumber,
costcenter_number: row.CostCenterCode
};
// Format Dates
row.DueDate = (row.DueDate) ? format(new Date(row.DueDate + '-0800'), 'MM/dd/yy') : '';
row.PromisedDate = (row.PromisedDate) ? format(new Date(row.PromisedDate + '-0800'), 'MM/dd/yy') : '';
row.ScheduledStart = (row.ScheduledStart) ? format(new Date(row.ScheduledStart + '-0800'), 'MM/dd/yy HH:mm') : '';
row.ScheduledEnd = (row.ScheduledEnd) ? format(new Date(row.ScheduledEnd + '-0800'), 'MM/dd/yy HH:mm') : '';
let signoffs = { signoff_id: 0, job_number: false, component_number: false, costcenter_number: false, ok_to_print: false, stepped: false, plated: false, ink_mixed: false, stock: false, die: false, mounted: false, cust_show: false, blanket: false };
const signoffData = await this.portal('signoffs')
.select(
'id AS signoff_id',
'job_number',
'component_number',
'costcenter_number',
'ok_to_print',
'stepped',
'plated',
'ink_mixed',
'stock',
'die',
'mounted',
'cust_show',
'blanket'
)
.where(query)
.orderBy('created_at', 'DESC');
if (signoffData[0]) { signoffs = Object.assign(signoffs, signoffData[0]); }
row = Object.assign(row, signoffs);
return row;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment