Jump to content

Complex Chunking Based on Fields and Record Number


Landisa

Recommended Posts

So we are trying to find a better way to run several hundred different coupon stacks. The customer wants the coupons stacked in "books" based on the number of coupons per book.

 

Here are the codes I have:

 

OnJobStart

FusionPro.Composition.chunksBreakStacks = true;

 

OnRecordStart

var jobNumber = Field("Job #") + "_" + Field("BMA Name");
var jobExtension = "." + (FusionPro.Composition.outputFormatExtension || "pdf");

if (FieldChanged("BMA Name") && FusionPro.Composition.repeatRecordNumber == 1)
   FusionPro.Composition.OpenNewOutputFile(jobNumber + jobExtension);

 

couponNumber

var strNumber = "<b><z newsize=10>N<z newsize=14><u><superscript>o</superscript></u><z newsize=12> </b>";
var bookCount = Field("# of books");
var couponPerBook = Field("# of coupons/book"); 

FusionPro.Composition.composeAllRecords = false; 
FusionPro.Composition.startRecordNumber = Field("start #"); 
FusionPro.Composition.endRecordNumber = Field("end #"); 
FusionPro.Composition.repeatRecordCount = Field("# of coupons"); 

return strNumber + FormatNumber ("0000", FusionPro.Composition.recordNumberInChunk);

 

This works great for stacking our coupons for each Ranch.

However, we now need to use the # of coupons/book to break up each part into a new book.

Example: Currently we see

Job#_Ranch1.pdf     (4000 coupons 1-4000)
Job#_Ranch2.pdf     (6000 coupons 1-6000)

 

What we are looking for are smaller chunks based on number of records per book and number of books or total number of coupons.

Example: We want to see

Job#_Ranch1_Book1     (2000 coupons 1-2000)
Job#_Ranch1_Book2     (2000 coupons 2001-4000)
Job#_Ranch2_Book1     (1000 coupons 1-1000)
Job#_Ranch2_Book2     (1000 coupons 1001-2000)
Job#_Ranch2_Book3     (1000 coupons 2001-3000)
Job#_Ranch2_Book4     (1000 coupons 3001-4000)
Job#_Ranch2_Book5     (1000 coupons 4001-5000)
Job#_Ranch2_Book6     (1000 coupons 5001-6000)

 

I have tried a few things, including for loops, extra if statements and while loops. So far I have been unsuccessful at getting the result we need.

 

I am assuming we need a variable "bookCount" to increase after each set so it doesn't overwrite the previous set.

 

Attached is the original code before the OnRecordStart was updated for you to work with.

 

Suggestions?

BMA Sample Coupons.zip

Link to comment
Share on other sites

What we are looking for are smaller chunks based on number of records per book and number of books or total number of coupons.

Example: We want to see

Job#_Ranch1_Book1     (2000 coupons 1-2000)
Job#_Ranch1_Book2     (2000 coupons 2001-4000)
Job#_Ranch2_Book1     (1000 coupons 1-1000)
Job#_Ranch2_Book2     (1000 coupons 1001-2000)
Job#_Ranch2_Book3     (1000 coupons 2001-3000)
Job#_Ranch2_Book4     (1000 coupons 3001-4000)
Job#_Ranch2_Book5     (1000 coupons 4001-5000)
Job#_Ranch2_Book6     (1000 coupons 5001-6000)

So you want to always break up the output into chunks of 1000 coupons? If it's always a fixed number, like 1000, then you can just go into the Composition Settings, on the Output tab, check the "Output to multiple files" box, and set the number of records to 1000.

 

Or is the number of coupons per chunk variable? If so, then you just need to change the condition here:

if (FieldChanged("BMA Name") && FusionPro.Composition.repeatRecordNumber == 1)
   FusionPro.Composition.OpenNewOutputFile(jobNumber + jobExtension);

To something like this:

if (FieldChanged("BMA Name") || FusionPro.Composition.repeatRecordNumber % couponPerBook == 1)
{
   var couponPerBook = Field("# of coupons/book");
   var jobNumber = Field("Job #") + "_" + Field("BMA Name") + "_Book" + Int((FusionPro.Composition.repeatRecordNumber-1) / couponPerBook);
   var jobExtension = "." + (FusionPro.Composition.outputFormatExtension || "pdf");
   FusionPro.Composition.OpenNewOutputFile(jobNumber + jobExtension);
}

Link to comment
Share on other sites

Or is the number of coupons per chunk variable? If so, then you just need to change the condition here:

if (FieldChanged("BMA Name") && FusionPro.Composition.repeatRecordNumber == 1)
   FusionPro.Composition.OpenNewOutputFile(jobNumber + jobExtension);

To something like this:

if (FieldChanged("BMA Name") || FusionPro.Composition.repeatRecordNumber % couponPerBook == 1)
{
   var couponPerBook = Field("# of coupons/book");
   var jobNumber = Field("Job #") + "_" + Field("BMA Name") + "_Book" + Int((FusionPro.Composition.repeatRecordNumber-1) / couponPerBook);
   var jobExtension = "." + (FusionPro.Composition.outputFormatExtension || "pdf");
   FusionPro.Composition.OpenNewOutputFile(jobNumber + jobExtension);
}

 

Yes, the chunks are a variable. I was happy with how this worked but the coupons don't continue the count after the book is output.

 

So now I see:

Job#_Ranch1_Book0     2000 coupons     (1-2000)
Job#_Ranch1_Book1     2000 coupons     (1-2000)

 

What I was hoping for was to continue the numbering sequence:

Job#_Ranch1_Book0     2000 coupons     (1-2000)
Job#_Ranch1_Book1     2000 coupons     (2001-4000)

 

Is there a way to keep the numbering sequential?

Link to comment
Share on other sites

Nevermind! I just had to eat some breakfast.

 

I used your book separating method and changed the couponNumber rule:

 

Old Rule

var strNumber = "<b><z newsize=10>N<z newsize=14><u><superscript>o</superscript></u><z newsize=12> </b>";

FusionPro.Composition.composeAllRecords = false; 
FusionPro.Composition.startRecordNumber = Field("start #"); 
FusionPro.Composition.endRecordNumber = Field("# of coupons"); 
FusionPro.Composition.repeatRecordCount = Field("# of coupons");

return strNumber + FormatNumber ("0000", FusionPro.Composition.recordNumberInChunk);

 

New Rule

var strNumber = "<b><z newsize=10>N<z newsize=14><u><superscript>o</superscript></u><z newsize=12> </b>";

FusionPro.Composition.composeAllRecords = false; 
FusionPro.Composition.startRecordNumber = Field("start #"); 
FusionPro.Composition.endRecordNumber = Field("# of coupons"); 
FusionPro.Composition.repeatRecordCount = Field("# of coupons");

return strNumber + FormatNumber ("0000", FusionPro.Composition.repeatRecordNumber);

 

By changing it from recordNumberInChunk to repeatRecordNumber, it kept the sequence set number per Ranch but continued to break correctly between books.

 

Thanks! ^^,

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...