NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

const paystub_url = 'https://www.paycomonline.net/v4/ee/web.php/check-listing/index/index#!check-listings';
const paystub_elements = ['select[id="yearCheck"]'];

page = await this.pre_navigate_to_item(page);
await this.ph.set_pdf_download(this.session, true);

await this.ph.goto(paystub_url, page, ['load'], 20000);

//Wait for Year Check Select
await this.ph.waitForSelector(paystub_elements[0], page, {
visible: true,
timeout: 15000
});

class Emp_1t24BkPa6ILBzz8JVjsZ4wBxfDW_Paystub_Iterator extends ItemIterator {

constructor(page, session_id) {
super(page);
this.session_id = session_id;
this.session = global.session_mgr.get_session(session_id);
this.elements = ['select[id="yearCheck"]', 'a[class="paystubSummary"]', 'select[id="dateAndNum"]', 'a[id="pdf-button"]'];
}

async init() {
this.paystubYearLinks = await this.get_paystub_year_links(this.page);
logger.info(`Paystubs Years Links => ${JSON.stringify(this.paystubYearLinks)}`);

this.num_of_items = this.paystubYearLinks.length;

logger.info(`Total Paystub Years => ${this.num_of_items}`);

if (this.num_of_items === 0) {
throw Controller.getError('general', 'notAvailable', SUPPORTED_ITEM_TYPE.paystub_file);
}

this.prev_year_idx = this.curr_year_paystub_idx = this.curr_year_total_paystub = -1;

this.curr_year_paystubs = [];

this.du = new DownloadUtils();
this.downloadPath = this.du.getDownloadPath(this.session_id);
await this.du.createDownloadDir(this.session_id);
await this.ph.downloadFileInitializer(this.downloadPath, this.page);
}

async next() {
await this.removeDownloadedFiles();

await this.select_year(this.page);

//if no paystub found for curr year

if (this.curr_year_total_paystubs === 0) {
this.index++;
return null;
}

await this.select_paystub(this.page);

await this.chk_for_next_year();

let files = await this.du.getDownloadFilesPath(this.session_id);
if (files.length === 0) {
logger.warn(await this.ph.get_page_content(this.page));
throw new Error(`File is not available in the download path for -> ${JSON.stringify(this.curr_year_paystubs[this.curr_year_paystub_idx])}, index -> ${this.index}`);
}

this.session.extract_file_path = files[0];
logger.debug(`session.extract_path => ${this.session.extract_file_path}`);
return this.page;
}

hasNext() {
logger.info(`Curr year idx ${this.index} , total years ${this.num_of_items}`); //will remove this afterwards
return (this.index < this.num_of_items);
}

async chk_for_next_year() {
logger.debug('Emp_1t24BkPa6ILBzz8JVjsZ4wBxfDW_Paystub_Iterator -> chk_for_next_year - started');

if (this.curr_year_paystub_idx === this.curr_year_total_paystubs) {
this.index++;
}
}

async re_init_paystubs(page) {
logger.debug('Emp_1t24BkPa6ILBzz8JVjsZ4wBxfDW_Paystub_Iterator -> re_init_paystubs - started');

this.curr_year_paystubs = await this.getSelectOptions(this.elements[2], page);
this.curr_year_total_paystubs = this.curr_year_paystubs.length;
this.curr_year_paystub_idx = 0;

logger.info(`Current year Paystub Types => ${JSON.stringify(this.curr_year_paystubs)}`);
logger.info(`Total Paystubs for current year=> ${this.curr_year_total_paystubs}`);
}

async getSelectOptions(selector, page) {
return await page.evaluate((selector) => {
let selectElements = Array.from(document.querySelectorAll(selector));
let options = [];
if (selectElements && selectElements.length > 0) {
options = Array.from(selectElements[0]).map(o => {
return {
text: `${o.text}`,
value: `${o.value}`
};
});
}
return options;
}, selector);
}

async get_paystub_year_links(page) {
logger.debug('Emp_1t24BkPa6ILBzz8JVjsZ4wBxfDW_Paystub_Iterator -> get_paystub_year_links - started');

await this.ph.waitForSelector(this.elements[0], page);
let yearOptions = await this.ph.getSelectOptions(this.elements[0], page);
yearOptions = yearOptions.filter(year => CommonUtils.isNumber(year.value));

let yearLinks = yearOptions.map(yearObj => `https://www.paycomonline.net/v4/ee/web.php/check-listing/index/index/${yearObj.value}#!check-listings`);
return yearLinks;
}

async select_year(page) {
logger.debug('Emp_1t24BkPa6ILBzz8JVjsZ4wBxfDW_Paystub_Iterator -> select_year - started');

if (this.index != this.prev_year_idx) {

await this.ph.goto(this.paystubYearLinks[this.index], page, ['load'], 20000);
await Promise.race([this.ph.waitForResponse('table=processingschedule', page, 'include'), this.ph.waitFor(10000)]);

try {
await this.ph.waitForSelector(this.elements[1], page, {
visible: true,
timeout: 15000
});
await this.ph.performClickAndNavigation(this.elements[1], page, {
timeout: 20000,
waitUntil: ['load']
});
} catch (e) {
logger.warn(e);
}

this.prev_year_idx = this.index;

//Wait for Date and Number Paystub Select

try {
await this.ph.waitForSelector(this.elements[2], page);
} catch (e) {
logger.warn(e);
}


await this.re_init_paystubs(page);
}
}



async removeDownloadedFiles() {
if (this.curr_year_paystub_idx > 0 && (this.curr_year_total_paystub > this.curr_year_paystub_idx)) {
let files = await this.du.getDownloadFilesPath(this.session_id);
if (files.length > 0) {
await this.du.emptyDownloadDir(this.session_id);
}
}
}

async select_paystub(page) {
logger.debug('Emp_1t24BkPa6ILBzz8JVjsZ4wBxfDW_Paystub_Iterator -> select_paystub - started');

if (this.curr_year_paystub_idx > 0 && (this.curr_year_total_paystubs > this.curr_year_paystub_idx)) {
await this.ph.waitForSelector(this.elements[2], page);
}

//click on curr year paystubs
await this.ph.performSingleSelect(this.elements[2], this.curr_year_paystubs[this.curr_year_paystub_idx++].value, page);
await Promise.race([this.ph.waitForNavigation(page), this.ph.waitFor(10000)]);

//Click on Print Paystub Button
await this.ph.waitForSelector(this.elements[3], page);
await this.ph.performClick(this.elements[3], page);
}

}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.