Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Dates

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 19th, 2013, 03:23 PM
brians brians is offline
Junior Community Member
 
Join Date: Dec 2011
Location: Cedar Rapids, Iowa
Posts: 18
Default Setting a turnaround level based on mail drop date?

Looking for assistance in creating a rule that will populate a field with a turnaround level based on input from the user into a Mail Drop Date field. Example: If the user chooses a mail drop date of Monday, February 25th, 2013 and today is Friday, February 22, 2013 the rule will set the turnaround field to Express 2 Business Days.

Rush 2 Business Days
Mail Drop Date <= 2 Business Days from Today

Express 3 Business Days
Mail Drop Date <= 3 Business Days from Today and > 2 Business Days

Standard 5 Business Days
Mail Drop Date >= 5 Business Days from Today

Since the input from the user can be controlled by the calendar function in Marcom I can set this to whatever format is easiest to code.

Thanks in advance for any help you can provide.
Reply With Quote
  #2  
Old February 20th, 2013, 05:34 AM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Setting a turnaround level based on mail drop date?

Google is your friend:
Code:
var dDate1 = Today();
var dDate2 = DateFromString("2/25/2013"); //(Field("MailDropDate"));
var iWeeks, iDateDiff, iAdjust = 0;
var result = '';

// error code if dates transposed
if (dDate2 < dDate1) return "Your drop date occurs in the past!";

var iWeekday1 = dDate1.getDay();
var iWeekday2 = dDate2.getDay();

// change Sunday from 0 to 7
iWeekday1 = (iWeekday1 == 0) ? 7 : iWeekday1;
iWeekday2 = (iWeekday2 == 0) ? 7 : iWeekday2;

// adjustment if both days on weekend
if ((iWeekday1 > 5) && (iWeekday2 > 5)) iAdjust = 1;

// only count weekdays
iWeekday1 = (iWeekday1 > 5) ? 5 : iWeekday1;
iWeekday2 = (iWeekday2 > 5) ? 5 : iWeekday2;

// calculate difference in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)
iWeeks = Math.floor((dDate2.getTime() - dDate1.getTime()) / 604800000)

if (iWeekday1 <= iWeekday2) {
    iDateDiff = (iWeeks * 5) + (iWeekday2 - iWeekday1)
} else {
    iDateDiff = ((iWeeks + 1) * 5) - (iWeekday1 - iWeekday2)
}

// take into account both days on weekend
iDateDiff -= iAdjust;

// add 1 because dates are inclusive
//iDateDiff = iDateDiff + 1;

// determine correct turnaround
if (iDateDiff <= 2) result = 'Rush 2 Business Days';
else if (iDateDiff >= 5) result = 'Standard 5 Business Days';
else result = 'Express 3 Business Days';

return result;
Note that I commented out the "inclusive day" since I would think that "today" would not be factored in when determining turnaround time, especially if order is placed end of day.
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #3  
Old February 20th, 2013, 09:26 AM
brians brians is offline
Junior Community Member
 
Join Date: Dec 2011
Location: Cedar Rapids, Iowa
Posts: 18
Default Re: Setting a turnaround level based on mail drop date?

This works perfectly in that it returns the value I'm look for however I'm not sure how I can now apply a price to the value in Marcom. My goal was to have the result of this rule populate a field that could then have a dynamic price attached. Is it possible to have a rule change the data and therefore make it visible to the intelligent forms?
Reply With Quote
  #4  
Old February 21st, 2013, 01:28 AM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Setting a turnaround level based on mail drop date?

It sounds like you are asking for logic that alters the content of your front end rather than a FusionPro-generated document. In that case, you might want to post this in the Marcom Central section for specific information. I am not an MC user so I can't help in that regard.
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #5  
Old February 21st, 2013, 01:30 AM
brians brians is offline
Junior Community Member
 
Join Date: Dec 2011
Location: Cedar Rapids, Iowa
Posts: 18
Default Re: Setting a turnaround level based on mail drop date?

Thanks Eric. I kind of thought that might be the case. Thanks again for getting me this far.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:23 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.