Jump to content

with extra data tables appearing


Landisa

Recommended Posts

My reporting form has been modified this year and I was trying out some new code that was a lot more condensed than my previous code.

 

However, it seems that the data table does not create a new one for each property but makes doubles and extras of the first table.

 

Can someone look at the code and forms and see what I missed?

I thought it had to do with clearing the data array but I can't figure out where I am running into trouble (probably because I have been staring at this code for weeks now). Any help would be greatly appreciated!

 

//Link to the external data file.  
//The '\t' is used to indicate TAB delimited data in this external data file
data = new ExternalDataFileEx("property.txt", "\t");

if (!data.valid)
{
  ReportError("Cannot successfully read/find the external data file.");
}

// Create empty
var tables = [];
var tbl = [];

//Get a count of the total number of records in the external data file
NumberOfRecords = data.recordCount;

var type = [
   ['Horses', 'Horses, Mules and Asses (ponies, donkeys, burros)*', 5.85],
   ['Cattle','Cattle (cows, bulls, yearlings)*', 2.29],
   ['Bison','Domestic Bison*', 6.38],
   ['Sheep','Sheep*', 0.54],
   ['Swine','Swine (report all swine three months of age or older)', 0.78], 
   ['Goats','Goats*', 0.54],
   ['Poultry','Poultry (chickens, turkeys, geese, ducks and other domestic birds raised as food or to produce feathers)', 0.05],
   ['Bees','Bees (number of hives or boards)', 0.41],
   ['Domestic','Alternative Livestock (privately owned caribou, mule deer, whitetail deer, elk, moose, antelope, mountain sheep, mountain goats indigenous to Montana)*', 26.23],    
   ['Ratites','Ratites (ostriches, rheas, emus)*', 9.37],
   ['Llamas','Llamas and Alpacas*' , 9.37]
];

//Now, loop through all records in the external data file and find the records that belong to the customer.
for (var n = 1; n <= NumberOfRecords; n++) 
{
   function ExField(field) { return data.GetFieldValue(n, field); }

   if (ExField("CID") == Field("Customer ID")) 
   {

       //Create Table
       var myTable = new FPTable;

       myTable.AddColumns(26500, 5800, 7500, 10800);

       tbl.push(["County: " + ExField("County Name"), "Property ID: " + ExField("Property ID"), "", ""]); // Title
       tbl.push(["Livestock Type", "A <br> Count", "B <br> Fee Amount", "C <br> Calculate Total"]); // Header

       type.forEach(function(s) 
       {
           var [field, description, price] = s;
           field = ExField(field);
           description = "<leading newsize = 120>" + description;
           price = "  x  " + FormatNumber('$00.00', price).replace('$0','$  ')+ " = ";
           tbl.push([description, '', price,'']);
       });

       // Footer
       tbl.push(["Add amounts in column C. <br><b>This is your total Per Capita Fee Amount due for this county.</b>", "", "", "<b>$</b>"]); 

       // Formatting 
       for (var i=0; i<tbl.length; i++) 
       {
           var row = myTable.AddRow();
           var cell = row.Cells[0];

           cell.PointSize = 11; 
           cell.Margins = new FPTableMargins;
           cell.Margins = {Bottom: 10, Top: 23, Left: 250, Right: 250};
           row.CopyCells (0,1,2,3);
           row.minHeight = 1500;

           myTable.ShadingColor1 = 'White';
           myTable.ShadingPct1 = 100;
           myTable.ShadingRepeat1 = 1;
           myTable.ShadingColor2 = 'Black 9%';
           myTable.ShadingPct2 = 100;
           myTable.ShadingRepeat2 = 1;
           myTable.ShadingType = 'ByRow'; //or “ByColumn”

           if (i == 0) 
           {
               cell.VAlign = 'Bottom';
               cell.Bold = 'On';  
           }

           if (i == 1) 
           {
               cell.PointSize = 10;
               cell.ShadeColor = "Brown";
               cell.ShadePct = 100;
               cell.TextColor = "White";
               cell.HAlign = "Center";
               cell.Bold = 'On';
               cell.SetBorders("Thin", "Black 25%","Top", "Bottom", "Right", "Left");
               row.minHeight = 3000;
               row.CopyCells (0,1,2,3);
           }

           if (i > 1) 
           {
               cell.Bold = 'Off';
               cell.SetBorders("Thin", "Black 25%","Top", "Bottom", "Right", "Left");
               cell.HAlign = "Left";
               row.minHeight = 1500;
               row.CopyCells (0,1,2,3);
           }

           if (i == 13) 
           {
               cell.PointSize = 10;
               cell.HStraddle = 3;
               cell.HAlign = "Right"; 
           }

           cell.VAlign = 'Middle';
           row.CopyCells (0,1,2,3);

           //Assign the content
           var [col1,col2,col3,col4] = tbl[i];
           row.SetContents(col1,col2,col3,col4);
       }

       myTable.Rows[0].Cells[1].HStraddle = 3;
       myTable.Rows[13].Cells[3].HAlign = "Left";

       // Push variable into Array
       tables.push(myTable.MakeTags()); 
   }
}
return tables.join('<br>');

Reporting Form 2017.zip

Edited by Landisa
Updated with Code snippet
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...