How to get sum of array in foreach in laravel 6 - arrays

from my controller sum is not working
public function show($id)
{
$workers = DB::table('workers')
->select('wrk_id','f_name','m_name','l_name')
;
$attendance = DB::table('attendance')->where('payroll_daily_id', $id)
->select('attendance.*','f_name','l_name','m_name',DB::raw('SUM(reg_hour)as tots'))
->rightjoinSub($workers,'worker', function($join){
$join->on('attendance.wrk_id','=','worker.wrk_id');
})
->groupBy('payroll_attn_id')
->get();
foreach($attendance as $key){
$fetch[$key->wrk_id]['wrk_id'] = $key->wrk_id;
$fetch[$key->wrk_id]['f_name'] = $key->f_name;
$fetch[$key->wrk_id]['l_name'] = $key->l_name;
$fetch[$key->wrk_id]['m_name'] = $key->m_name;
$fetch['total_work_hours'] = $key->tots;
$fetch[$key->wrk_id]['date'][$key->date]['work_hours'] = $key->reg_hour;
}
return $fetch;
}
this is the result total_work_hours display only 8 instead of 56
2: {wrk_id: 2, f_name: "John", l_name: "Doe", m_name: null,…}
date: {2020-09-27: {work_hours: 8}, 2020-09-28: {work_hours: 8}, 2020-09-29: {work_hours: 8},…}
2020-09-27: {work_hours: 8}------------------
2020-09-28: {work_hours: 8}------------------
2020-09-29: {work_hours: 8}------------------
2020-09-30: {work_hours: 8}------------------ TOTAL OF THIS IS 56
2020-10-01: {work_hours: 8}------------------
2020-10-02: {work_hours: 8}------------------
2020-10-03: {work_hours: 8}-----------------
f_name: "John"
l_name: "Doe"
m_name: null
wrk_id: 2
total_work_hours: "8" <------------- 56 is the total off work_hours from array

try this
$fetch = [];
foreach($attendance as $key){
if(!isset($fetch[$key->wrk_id]['total_work_hours'])){
$fetch[$key->wrk_id]['total_work_hours'] = 0;
}
$fetch[$key->wrk_id]['wrk_id'] = $key->wrk_id;
$fetch[$key->wrk_id]['f_name'] = $key->f_name;
$fetch[$key->wrk_id]['l_name'] = $key->l_name;
$fetch[$key->wrk_id]['m_name'] = $key->m_name;
$fetch['s'] = $key->tots;
$fetch[$key->wrk_id]['date'][$key->date]['work_hours'] = $key->reg_hour;
$fetch[$key->wrk_id]['total_work_hours'] += $key->reg_hour;
}
return $fetch;

Use foreach like this:
foreach($attendance as $key){
if(empty($fetch[$key->wrk_id]['total_work_hours'])){
$fetch[$key->wrk_id]['total_work_hours'] = 0;
}
$fetch[$key->wrk_id]['wrk_id'] = $key->wrk_id;
$fetch[$key->wrk_id]['f_name'] = $key->f_name;
$fetch[$key->wrk_id]['l_name'] = $key->l_name;
$fetch[$key->wrk_id]['m_name'] = $key->m_name;
$fetch['s'] = $key->tots;
$fetch[$key->wrk_id]['total_work_hours'] += $key->reg_hour;
}

Related

Add picture to objects from array table in Lua

I am creating 8 images using Cheat Engine Lua script and I want to add some pictures to the images from an array table.
the_famous = {
{photo = "AlbertEinstein.jpg", nickName = "einstein", actorName = "Albert Einstein", profession = "Physicist", creation = "Theory of relativity", nationality = "Germany", life = "14 March 1879 - 18 April 1955"},
{photo = "Mozart.jpg", nickName = "mozart", actorName = "Wolfgang Amadeus Mozart", profession = "Classical Music Composer", creation = "Symphony No.40", nationality = "Austria", life = "27 January 1756 – 5 December 1791"},
{photo = "Guevara.jpg", nickName = "guevara", actorName = "Ernesto 'Che' Guevara", profession = "Revolutionary", creation = "Cuban Revolution", nationality = "Cuba, Argentina ", life = "14 June 1928 - 9 October 1967"},
{photo = "BruceLee.jpg", nickName = "bruce lee", actorName = "Bruce Lee (Lee Jun Fan)", profession = "Martial Artist", creation = "Father of MMA", nationality = "Hongkong, America", life = "27 November 1940 - 20 July 1973"},
{photo = "Marilyn.jpg", nickName = "marilyn monroe", actorName = "Marilyn Monroe (Norma Jeane Mortenson)", profession = "Artist", creation = "The most famous sex symbol", nationality = "America", life = "1 June 1926 - 5 August 1962"}}
function start()
if #the_famous ~= 0 then
the_famous.ItemIndex = 0
local idx = the_famous.ItemIndex
for i = 1, 8 do
local idx = tableTemp.ItemIndex
local img = string.format('image1'..i) -- images name start with 'image11' till 'image18'
local pic = the_famous[i].photo
img.Picture.loadFromFile(path_to_images_stored..tostring(pic))
img.Hint = the_famous[i].nickname
idx = idx + 1
end
end
end
But the function above doesn't work. How I can do it properly?
Solved
I have change my script:
local cleft = 20
local ctop = 20
function getCategory(sender)
local cat = sender.Name
if cat == 'btnFamous' then
while #tableTemp ~= 0 do rawset(tableTemp, #tableTemp, nil) end
tableTemp = {}
for z=1, #the_famous do tableTemp[z] = the_famous[z] end
else
return nil
end
for i = 1, 24 do
local newImg = createImage(mPanel)
newImg.width = 90
newImg.height = 90
newImg.top = ctop
newImg.left = cleft
newImg.Stretch = true
newImg.Picture.loadFromFile(famous_img..tostring(tableTemp[i].photo))
newImg.showHint = true
newImg.Hint = tostring(tableTemp[i].nickName)
newImg.Name = 'pic00'..i
cleft = cleft + 100
if i == 8 or i == 16 then
cleft = 20
ctop = ctop + 100
end
newImg.OnMouseEnter = function()
hglight.visible=true
hglight.setPosition(newImg.Left-10, newImg.Top-10)
end
newImg.OnMouseLeave = function()
hglight.visible=false
hglight.setPosition(newImg.Left-10, newImg.Top-10)
end
end
end
All works properly

AngularJS Getting Data response in console as null but in Postman is not null

Postman and Direct URL Response
"MenuId": 2010,
"KitchenId": 2005,
"Categoryid": 1,
"CategoryName": "Starters",
"SubCategoryId": 1,
"SubCategoryName": "Veg Starters",
"Name": "Paneer Kabab",
"Description": "Paneer fried",
"ImageURL": "noimage.png",
"Foodtype": 1,
"NetPrice": 70.00,
"NetGST": 3.50,
"NetTotal": 83.50,
"ListPrice": 84.00,
"ListGST": 4.20,
"ListTotal": 99.20,
"PackingCharge": 11.00,
"Discount": null,
"TotalOrders": 0.00,
"Ratings": null,
"MenuStatus": 1,
"VegTypeId": 1,
"GetButton_no": [
{
**"ButtonNo_No": 99.20**
}
],
Browser Console
{ "MenuId": 2010,
"KitchenId": 2005,
"Categoryid": 1,
"CategoryName": "Starters",
"SubCategoryId": 1,
"SubCategoryName": "Veg Starters",
"Name": "Paneer Kabab",
"Description": "Paneer fried",
"ImageURL": "noimage.png",
"Foodtype": 1,
"NetPrice": 70.00,
"NetGST": 3.50,
"NetTotal": 83.50,
"ListPrice": 84.00,
"ListGST": 4.20,
"ListTotal": 99.20,
"PackingCharge": 11.00,
"Discount": null,
"TotalOrders": 0.00,
"Ratings": null,
"MenuStatus": 1,
"VegTypeId": 1,
"GetButton_no": [
{
**"ButtonNo_No": null**
}
],
}
Why is the same API Behaving different behaviour , I am using Entity Framework for that.
public IEnumerable<KitchenMenu_CategoryModel> GetKitchenMenubyKitchennew(int kid,string Username)
{
var result = db.tblKitchens.Where(x => x.Id == kid).Select(x => new KitchenMenu_CategoryModel
{
KitchenId = x.Id,
KitchenName = x.KitchenName,
KitchenType = x.KitchenType,
Area = x.Area,
Address1 = x.Address1,
Address2 = x.Address2,
//CId = x.CityId,
Pincode = x.Pincode,
Email = x.Email,
Website = x.Website,
Landline = x.Landline,
Halal = x.Halal,
Category = x.Category,
Branches = x.Branches,
AvgCost = x.AvgCost,
Fssai = x.Fssai,
FssaiPath = x.FssaiPath,
RegisterStatus = x.RegisterStatus,
Logo = db.tblKitchenMedias.Where(r => r.KitchenId == x.Id).Select(r => r).FirstOrDefault().Logo,
Banner = db.tblKitchenMedias.Where(s => s.KitchenId == x.Id).Select(s => s).FirstOrDefault().Banner,
GetCategory = db.tblGetCategories.Where(y => y.Kitchenid == x.Id).Select(y => new CategoryModel
{
CategoryId = y.Categoryid,
Kitchenid = y.Kitchenid,
CategoryName = y.tblCategory.CategoryName,
SubCateogry = db.tblGetSubCategories.Where(z => z.Categoryid == y.Categoryid && z.Kitchenid == y.Kitchenid).Select(z => new SubCategoryModel
{
Categoryid = z.Categoryid,
SubCategoryName = z.tblSubCategory.SubCategoryName,
Kitchenid = z.Kitchenid,
GetMenu = db.tblMenus.Where(a => a.SubCategoryId == z.SubCategoryid && a.KitchenId == z.Kitchenid).Select(a => new MenuModel
{
MenuId = a.MenuId,
Name = a.Name,
Description = a.Description,
Discount = a.Discount,
ImageURL = a.ImageURL,
ListGST = a.ListGST,
ListPrice = a.ListPrice,
ListTotal = a.ListTotal,
NetGST = a.NetGST,
NetPrice = a.NetPrice,
TotalOrders = a.TotalOrders,
KitchenId = a.KitchenId,
SubCategoryId = a.SubCategoryId,
MenuStatus = a.MenuStatus,
NetTotal = a.NetTotal,
VegTypeId = a.VegTypeId,
Categoryid = a.Categoryid,
CategoryName = a.tblCategory.CategoryName,
SubCategoryName = a.tblSubCategory.SubCategoryName,
Ratings = a.Ratings,
Foodtype = a.Foodtype,
PackingCharge = a.PackingCharge,
GetButton_no =db.tblcarts.Where(d => d.Username == Username && d.KitchenId == kid && d.MenuId == a.MenuId).Select(d => new ButtonModel
{
ButtonNo_No =d.TotalPrice,
}
).ToList(),
//ButtonNo_No = db.tblcarts.Where(d => d.Username == Username && d.KitchenId == a.KitchenId && d.MenuId == a.MenuId).Select(d => d).FirstOrDefault().Quantity,
//Button_No =db.spCountCartButton(Username,a.KitchenId,a.MenuId).Select(d=>d).FirstOrDefault(),
GetMenuAttribute = db.tblMenuAttributes.Where(b => b.Menuid == a.MenuId).Select(b => new MenuAttributeModel
{
MenuAttributeId = b.MenuAttributeId,
Menuid = b.Menuid,
AttributeType = b.AttributeType,
MenuAttribute = b.MenuAttribute,
MenuDescription = b.MenuDescription,
NetPrice = b.NetPrice,
NetGST = b.NetGST,
NetTotal = b.NetTotal,
ListPrice = b.ListPrice,
ListGST = b.ListGST,
ListTotal = b.ListTotal,
PackingCharge = b.PackingCharge,
}
).ToList(),
}
).ToList(),
}
).ToList(),
}
).ToList(),
}
).ToList();
return result;
}
--API Controller
[Route("api/GetMenuBykidnew")]
[HttpGet]
public HttpResponseMessage GetMenuBykid(int kid, string Username)
{
//var data = new List();
ApiBusiness ApiBus = new ApiBusiness();
var result = ApiBus.GetKitchenMenubyKitchennew(kid, Username);
return new HttpResponseMessage()
{
Content = new StringContent(JArray.FromObject(result).ToString(), Encoding.UTF8, "application/json")
};
}
The response is very strange getting different response in browser console and postman

variable length line in a file deletion in C

I have a file main.txt and I want to delete a line in this file that contains a number passed as an argument to the program.
My code:
FILE *temp = fopen("main.txt","r");
FILE *copy = fopen("temp.txt","w+");
char line[25]; //lines won't be more than this length
while(fgets(line, sizeof(line), temp)!=NULL)
{
char *s;
s = strstr(line, argv[2]));
if(s!=NULL)
continue;
else
fputs(line,copy);
}
fclose(temp);
fclose(copy);
remove("main.txt");
rename("temp.txt", "main.txt");
Case where this fails:
Currently my file has:
echo hello 24224
echo test123 24196
echo bye 13279
When I try to remove the line with 24196, it doesn't copy the last line to the new file. Using ltrace shows that after strstr returns a non NULL value, fgets gets an emty string. How can I fix this, what is going wrong here?
__libc_start_main(0x402636, 3, 0x7ffcee2a2078, 0x4036b0 <unfinished ...>
strcmp("unmanage", "unmanage") = 0
fopen("pid1.txt", "r") = 0x19ee010
fopen("temp.txt", "w+") = 0x19ee240
fgets("echo hello 30876\n", 25, 0x19ee010) = 0x7ffcee2a1f60
strstr("echo hello 30876\n", "5785") = nil
fputs("echo hello 30876\n", 0x19ee240) = 1
fgets("echo lame 9047\n", 25, 0x19ee010) = 0x7ffcee2a1f60
strstr("echo lame 9047\n", "5785") = nil
fputs("echo lame 9047\n", 0x19ee240) = 1
fgets("echo trial 5785\n", 25, 0x19ee010) = 0x7ffcee2a1f60
strstr("echo trial 5785\n", "5785") = "5785\n"
fgets("", 25, 0x19ee010) = 0x7ffcee2a1f60
strstr("", "5785") = nil
fputs("", 0x19ee240) = 1
fgets("", 25, 0x19ee010) = 0x7ffcee2a1f60
strstr("", "5785") = nil
fputs("", 0x19ee240) = 1
fgets("", 25, 0x19ee010) = 0x7ffcee2a1f60
strstr("", "5785") = nil
fputs("", 0x19ee240) = 1
fgets("", 25, 0x19ee010) = 0x7ffcee2a1f60
strstr("", "5785") = nil
fputs("", 0x19ee240) = 1
fgets("", 25, 0x19ee010) = 0
fclose(0x19ee010) = 0
fclose(0x19ee240) = 0
remove("pid1.txt") = 0
rename("temp.txt", "pid1.txt") = 0
atoi(0x7ffcee2a320f, 0x403aca, 0, 0x7fde8ca22367) = 5785
kill(5785, SIGTERM) = 0
+++ exited (status 0) +++

Most Efficient Ways To Compare Multiple Array Values in VBA?

Before I begin, let me say that I know this probably isn't best done in excel and VBA, but my hands are tied in that regard.
I have a spreadsheet of 29 columns (always), and anywhere between 100 and 10,000 rows each day.
I need a way to automatically move rows from one sheet to another based on multiple criteria. The basic logic is that it needs to search the first sheet, and if C OR D equal a certain text value, AND Y contains a certain numeric value, it needs to be added to the second sheet and removed from the first.
The problem is that I've built a test version that only looks at ONE of the three criteria, and it is already very slow - If I had two more arrays and if/and/or logic, I don't think this is going to be usable on the 10,000 row days.
What can I do to speed this up? I feel like there has to be a better/faster way than arrays and for loops. I'm very much a novice, so I'm sure this is a very bad solution.
Option Explicit
Sub MacroSoFar()
Dim lColumnLength As Long
Dim intArrayCounter As Integer
Dim TestArray(165) As String
TestArray(0) = "4"
TestArray(1) = "5"
TestArray(2) = "6"
TestArray(3) = "7"
TestArray(4) = "8"
TestArray(5) = "9"
TestArray(6) = "10"
TestArray(7) = "11"
TestArray(8) = "12"
TestArray(9) = "14"
TestArray(10) = "19"
TestArray(11) = "20"
TestArray(12) = "21"
TestArray(13) = "25"
TestArray(14) = "30"
TestArray(15) = "35"
TestArray(16) = "36"
TestArray(17) = "37"
TestArray(18) = "41"
TestArray(19) = "42"
TestArray(20) = "43"
TestArray(21) = "46"
TestArray(22) = "47"
TestArray(23) = "48"
TestArray(24) = "51"
TestArray(25) = "52"
TestArray(26) = "53"
TestArray(27) = "60"
TestArray(28) = "63"
TestArray(29) = "65"
TestArray(30) = "66"
TestArray(31) = "67"
TestArray(32) = "68"
TestArray(33) = "69"
TestArray(34) = "70"
TestArray(35) = "71"
TestArray(36) = "72"
TestArray(37) = "73"
TestArray(38) = "74"
TestArray(39) = "75"
TestArray(40) = "76"
TestArray(41) = "77"
TestArray(42) = "78"
TestArray(43) = "79"
TestArray(44) = "80"
TestArray(45) = "81"
TestArray(46) = "82"
TestArray(47) = "83"
TestArray(48) = "84"
TestArray(49) = "85"
TestArray(50) = "86"
TestArray(51) = "87"
TestArray(52) = "88"
TestArray(53) = "89"
TestArray(54) = "90"
TestArray(55) = "91"
TestArray(56) = "92"
TestArray(57) = "93"
TestArray(58) = "94"
TestArray(59) = "96"
TestArray(60) = "97"
TestArray(61) = "98"
TestArray(62) = "99"
TestArray(63) = "101"
TestArray(64) = "102"
TestArray(65) = "103"
TestArray(66) = "106"
TestArray(67) = "107"
TestArray(68) = "108"
TestArray(69) = "109"
TestArray(70) = "111"
TestArray(71) = "112"
TestArray(72) = "113"
TestArray(73) = "115"
TestArray(74) = "116"
TestArray(75) = "117"
TestArray(76) = "118"
TestArray(77) = "121"
TestArray(78) = "122"
TestArray(79) = "125"
TestArray(80) = "129"
TestArray(81) = "130"
TestArray(82) = "131"
TestArray(83) = "132"
TestArray(84) = "133"
TestArray(85) = "134"
TestArray(86) = "137"
TestArray(87) = "138"
TestArray(88) = "142"
TestArray(89) = "143"
TestArray(90) = "144"
TestArray(91) = "145"
TestArray(92) = "146"
TestArray(93) = "147"
TestArray(94) = "155"
TestArray(95) = "156"
TestArray(96) = "157"
TestArray(97) = "158"
TestArray(98) = "159"
TestArray(99) = "161"
TestArray(100) = "162"
TestArray(101) = "169"
TestArray(102) = "170"
TestArray(103) = "173"
TestArray(104) = "174"
TestArray(105) = "175"
TestArray(106) = "176"
TestArray(107) = "180"
TestArray(108) = "181"
TestArray(109) = "182"
TestArray(110) = "183"
TestArray(111) = "184"
TestArray(112) = "185"
TestArray(113) = "186"
TestArray(114) = "187"
TestArray(115) = "188"
TestArray(116) = "189"
TestArray(117) = "190"
TestArray(118) = "192"
TestArray(119) = "193"
TestArray(120) = "194"
TestArray(121) = "195"
TestArray(122) = "196"
TestArray(123) = "201"
TestArray(124) = "202"
TestArray(125) = "205"
TestArray(126) = "206"
TestArray(127) = "207"
TestArray(128) = "208"
TestArray(129) = "211"
TestArray(130) = "212"
TestArray(131) = "214"
TestArray(132) = "215"
TestArray(133) = "217"
TestArray(134) = "218"
TestArray(135) = "220"
TestArray(136) = "221"
TestArray(137) = "222"
TestArray(138) = "223"
TestArray(139) = "224"
TestArray(140) = "225"
TestArray(141) = "226"
TestArray(142) = "228"
TestArray(143) = "229"
TestArray(144) = "230"
TestArray(145) = "235"
TestArray(146) = "236"
TestArray(147) = "237"
TestArray(148) = "240"
TestArray(149) = "241"
TestArray(150) = "242"
TestArray(151) = "244"
TestArray(152) = "249"
TestArray(153) = "250"
TestArray(154) = "251"
TestArray(155) = "255"
TestArray(156) = "256"
TestArray(157) = "259"
TestArray(158) = "260"
TestArray(159) = "262"
TestArray(160) = "263"
TestArray(161) = "264"
TestArray(162) = "265"
TestArray(163) = "266"
TestArray(164) = "267"
TestArray(165) = "269"
For intArrayCounter = 0 To 165 Step 1
For lColumnLength = Cells(Rows.Count, 25).End(xlUp).Row To 1 Step -1
If InStr(Cells(lColumnLength, 25), TestArray(intArrayCounter)) > 0 Then
Range("a" & lColumnLength & ":AC" & lColumnLength).Copy Sheet10.Cells(Rows.Count, 1).End(xlUp).Offset(1)
Cells(lColumnLength, 29).EntireRow.Delete
End If
Next
Next
End Sub
I haven't tested this, but I got to run.
But it may give you some food for thought.
Option Explicit
Sub MacroSoFar()
Dim lColumnLength As Long
Dim intArrayCounter As Integer
Dim TestArray(165) As String
TestArray(0) = "4"
TestArray(1) = "5"
TestArray(2) = "6"
TestArray(3) = "7"
TestArray(4) = "8"
TestArray(5) = "9"
TestArray(6) = "10"
TestArray(7) = "11"
TestArray(8) = "12"
TestArray(9) = "14"
TestArray(10) = "19"
TestArray(11) = "20"
TestArray(12) = "21"
TestArray(13) = "25"
TestArray(14) = "30"
TestArray(15) = "35"
TestArray(16) = "36"
TestArray(17) = "37"
TestArray(18) = "41"
TestArray(19) = "42"
TestArray(20) = "43"
TestArray(21) = "46"
TestArray(22) = "47"
TestArray(23) = "48"
TestArray(24) = "51"
TestArray(25) = "52"
TestArray(26) = "53"
TestArray(27) = "60"
TestArray(28) = "63"
TestArray(29) = "65"
TestArray(30) = "66"
TestArray(31) = "67"
TestArray(32) = "68"
TestArray(33) = "69"
TestArray(34) = "70"
TestArray(35) = "71"
TestArray(36) = "72"
TestArray(37) = "73"
TestArray(38) = "74"
TestArray(39) = "75"
TestArray(40) = "76"
TestArray(41) = "77"
TestArray(42) = "78"
TestArray(43) = "79"
TestArray(44) = "80"
TestArray(45) = "81"
TestArray(46) = "82"
TestArray(47) = "83"
TestArray(48) = "84"
TestArray(49) = "85"
TestArray(50) = "86"
TestArray(51) = "87"
TestArray(52) = "88"
TestArray(53) = "89"
TestArray(54) = "90"
TestArray(55) = "91"
TestArray(56) = "92"
TestArray(57) = "93"
TestArray(58) = "94"
TestArray(59) = "96"
TestArray(60) = "97"
TestArray(61) = "98"
TestArray(62) = "99"
TestArray(63) = "101"
TestArray(64) = "102"
TestArray(65) = "103"
TestArray(66) = "106"
TestArray(67) = "107"
TestArray(68) = "108"
TestArray(69) = "109"
TestArray(70) = "111"
TestArray(71) = "112"
TestArray(72) = "113"
TestArray(73) = "115"
TestArray(74) = "116"
TestArray(75) = "117"
TestArray(76) = "118"
TestArray(77) = "121"
TestArray(78) = "122"
TestArray(79) = "125"
TestArray(80) = "129"
TestArray(81) = "130"
TestArray(82) = "131"
TestArray(83) = "132"
TestArray(84) = "133"
TestArray(85) = "134"
TestArray(86) = "137"
TestArray(87) = "138"
TestArray(88) = "142"
TestArray(89) = "143"
TestArray(90) = "144"
TestArray(91) = "145"
TestArray(92) = "146"
TestArray(93) = "147"
TestArray(94) = "155"
TestArray(95) = "156"
TestArray(96) = "157"
TestArray(97) = "158"
TestArray(98) = "159"
TestArray(99) = "161"
TestArray(100) = "162"
TestArray(101) = "169"
TestArray(102) = "170"
TestArray(103) = "173"
TestArray(104) = "174"
TestArray(105) = "175"
TestArray(106) = "176"
TestArray(107) = "180"
TestArray(108) = "181"
TestArray(109) = "182"
TestArray(110) = "183"
TestArray(111) = "184"
TestArray(112) = "185"
TestArray(113) = "186"
TestArray(114) = "187"
TestArray(115) = "188"
TestArray(116) = "189"
TestArray(117) = "190"
TestArray(118) = "192"
TestArray(119) = "193"
TestArray(120) = "194"
TestArray(121) = "195"
TestArray(122) = "196"
TestArray(123) = "201"
TestArray(124) = "202"
TestArray(125) = "205"
TestArray(126) = "206"
TestArray(127) = "207"
TestArray(128) = "208"
TestArray(129) = "211"
TestArray(130) = "212"
TestArray(131) = "214"
TestArray(132) = "215"
TestArray(133) = "217"
TestArray(134) = "218"
TestArray(135) = "220"
TestArray(136) = "221"
TestArray(137) = "222"
TestArray(138) = "223"
TestArray(139) = "224"
TestArray(140) = "225"
TestArray(141) = "226"
TestArray(142) = "228"
TestArray(143) = "229"
TestArray(144) = "230"
TestArray(145) = "235"
TestArray(146) = "236"
TestArray(147) = "237"
TestArray(148) = "240"
TestArray(149) = "241"
TestArray(150) = "242"
TestArray(151) = "244"
TestArray(152) = "249"
TestArray(153) = "250"
TestArray(154) = "251"
TestArray(155) = "255"
TestArray(156) = "256"
TestArray(157) = "259"
TestArray(158) = "260"
TestArray(159) = "262"
TestArray(160) = "263"
TestArray(161) = "264"
TestArray(162) = "265"
TestArray(163) = "266"
TestArray(164) = "267"
TestArray(165) = "269"
Dim oSheet As Variant, nSheet As Variant, oList As New Collection, nList As New Collection
oSheet = Range("A1:AC" & Cells(Rows.Count, 25).End(xlUp).Row).Value
For intArrayCounter = 0 To 165 Step 1
For lColumnLength = Cells(Rows.Count, 25).End(xlUp).Row To 1 Step -1
If InStr(oSheet(lColumnLength, 25), TestArray(intArrayCounter)) > 0 Then
' Add to list in order
nList.Add Range("a" & lColumnLength & ":AC" & lColumnLength).Value
Else
' Add to list in reverse order
oList.Add Range("a" & lColumnLength & ":AC" & lColumnLength).Value
End If
Next
Next
For i = oList.Count To 1 Step -1
For j = 1 To 29
oSheet(i, j) = oList(i)(1, j)
Next j
Next i
Range("A1:AC" & Cells(Rows.Count, 25).End(xlUp).Row) = oSheet
Range("A" & oList.Count + 1 & ":A" & Cells(Rows.Count, 25).End(xlUp).Row).EntireRow.Delete Shift:=xlUp
nSheet = Sheet10.Range("A1:AC" & nList.Count).Offset(Sheet10.Range("A" & Sheet10.UsedRange.Rows.Count).End(xlUp).Row).Value
For i = nList.Count To 1
For j = 1 To 29
nSheet(i, j) = nList(i)(1, j)
Next j
Next i
Sheet10.Range("A1:AC" & nList.Count).Offset(Sheet10.Range("A" & Sheet10.UsedRange.Rows.Count).End(xlUp).Row) = nSheet
Set nList = Nothing: Set oList = Nothing:Set oSheet = Nothing: Set nSheet = Nothing
End Sub

TCPDF: Prints Extra Blank PDF Page on Firefox only

I am viewing pdf files for printing, using TCPDF on CakePHP 2.4.
All browsers print exactly the same expected results, in addition to Adobe Acrobat reader too. The only exception is FireFox! It adds an additional blank page. I tried all suggested solutions mentioned in other questions here (and there), and none worked.
Here is my code:
<?php
App::import('Vendor', 'xtcpdf');
header('Content-type: application/pdf');
//see tcpdf_config.php for constants definitions
$pdf = new XTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', FALSE);
// set margins
$PDF_MARGIN_LEFT = $PDF_MARGIN_TOP = $PDF_MARGIN_RIGHT = $PDF_MARGIN_BOTTOM = 0;
$pdf->SetMargins($PDF_MARGIN_LEFT, $PDF_MARGIN_TOP, $PDF_MARGIN_RIGHT, $PDF_MARGIN_BOTTOM);
$pdf->setPrintHeader(FALSE); //$pdf->SetHeaderMargin(25);
$pdf->setPrintFooter(FALSE); //$pdf->SetFooterMargin(25);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->setFontSubsetting(FALSE);
$pdf->SetAutoPageBreak(TRUE, 0);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->addPage('L', 'Letter');
//****************** Completion Image *************************************//
$pdf->Image('/img/completion.png', $x = -10, $y = 34, $w = 240, $h = 30, $type = 'PNG', $link = '', $align = 'C', $resize = TRUE, $dpi = 900, $palign = 'C', $ismask = false, $imgmask = false, $border = 0, $fitbox = TRUE, $hidden = false, $fitonpage = TRUE);
//************************************************** TITLE Body **************************************************//
$pdf->SetFont('times', '', 20);
$title = $information['title'] ;
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 0, $y = 66, $title, $border = 0, $ln = 0, $fill = 0, $reseth = true, $align = 'C', $autopadding = true);
//****************** Description *********************************//
$pdf->SetFont('times', 'I', 16);
$description = 'bla bla bla bla bla';
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 0, $y = 93, $description, $border = 0, $ln = 0, $fill = 0, $reseth = true, $align = 'C', $autopadding = TRUE);
//************************** NAME **********************************//
$pdf->SetFont('times', 'B', 24);
$fullName = $information['Student']['first_name'] . ' ' . (!empty($information['Student']['middle_initial']) ? ($information['Student']['middle_initial'] . ' ') : '') . $certificate['Student']['last_name'];
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 0, $y = 127, $fullName, $border = false, $ln = 0, $fill = 0, $reseth = true, $align = 'C', $autopadding = FALSE);
//***************** Line/OFFICE ************************//
$pdf->SetFont('times', 'B', 12);
$office = '__________________________________________________<br/> Bla Bla Bla <br/>Office of bla bla blat<br/>bla bla bla bla';
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 3, $y = 151, $office, $border = 0, $ln = 10, $fill = 0, $reseth = FALSE, $align = 'C', $autopadding = FALSE);
//******************************* Certificate No. ************************************//
$pdf->SetFont('times', 'B', 10);
$certNo = 'No. ' . $information['Certificate']['certificate_No'];
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 32, $y = 154, $certNo, $border = 0, $ln = 0, $fill = 0, $reseth = FALSE, $align = 'L', $autopadding = false);
//*************************** Date of Issuance ****************************//
$pdf->SetFont('times', '', 10);
$issueDate = 'Date of Issuance: ' . date('F, Y', strtotime($information['Certificate']['award_date']));
$pdf->writeHTMLCell($w = 0, $h = 0, $x = 31, $y = 157, $issueDate, $border = 0, $ln = 0, $fill = 0, $reseth = false, $align = 'L', $autopadding = FALSE);
echo $pdf->Output('PDF' . $information['Certificate']['certificate_number'] . '.pdf', 'I');
$pdf->endPage();
questions I looked at:
Extra blank page with TCPDF
how TCPDF prevent the extra blank page
Firefox prints extra blank page
I found no documentation, no articles, no one can explain such weird behavior.
After all, an extra blank paper won't do any harm!

Resources