php undefined variables error when displaying pdf with mpdf - include

i have been in crisis for over 2 days with this pdf thing.Its not showing any error in the resulting action page,still not displaying in pdf document.Can anyone plz sort this this out, maybe a simple one i guess not sure.The code is below.
Anyways thanks in advance,all.
<?php
if(isset($_POST['email'])){
$email = $_POST['email'];
$fileno = $_POST['fileno'];
$header = $_POST['header'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$stime = $_POST['stime'];
$venue = $_POST['venue'];
$meettype = $_POST['meettype'];
$Itchair = $_POST['Itchair'];
$mem_pres = $_POST['mem_pres'];
$invite = $_POST['invite'];
$head = $_POST['head'];
$slno = $_POST['slno'];
$subject = $_POST['subject'];
$decision = $_POST['decision'];
$incharge = $_POST['incharge'];
$date = $_POST['date'];
$remarks = $_POST['remarks'];
}
include("MPDF54/mpdf.php");
$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0;
$mpdf->WriteHTML(file_get_contents("http://localhost/Bescom/besc_latest.php?email=$email&fileno=$fileno&header=$header&day=$day&month=$month&year=$year&stime=$stime&venue=$venue&meettype=$meettype&Itchair=$Itchair&mem_pres=$mem_pres&invite=$invite&head=$head&slno=$slno&subject=$subject&decision=$decision&date=$date&incharge=$incharge&remarks=$remarks"));
$mpdf->Output();
?>

Add following at top of mpdf.php
error_reporting(0);
This will resolved the issue.

Related

Loop through collection in laravel and get specific data from the collection

I'm trying to go through a collection and I need to get a list of products according to certain keys. but I get the following error when I print the list with dd:
"array_key_exists(): The first argument should be either a string or an integer"
this is my function
public function reemplazaCostoZona($zona, $destino, $especie, $costo, $transporCollect){
$productos = $transporCollect->where([['zona',$zona],['destino', $destino],['especie',$especie]])
->pluck('producto');
dd($productos );
}
Collection:
I need to obtain the list of products for destination zone and species, That is to say that for my example of collection, for zone 1 destination 5 specie 1 I would have in my list product 1 and there may be more.
function where Im obtain collection:
public function storeTranspor3($request){
DB::table('transpor')->truncate();
$var = DB::select("select flu.zona, flu.destino, flu.producto, pro.especie, sup.codigo, dtr.cod_fundo, sup.sup_ha, dtr.dist_pavimento, dtr.dist_no_pavimento, dtr.peaje
from flujos flu
left join super sup on (sup.zona = flu.zona)
left join d_transporte dtr on (dtr.cod_fundo = (sup.codigo / 1000000) and dtr.destino = flu.destino)
left join productos pro on (pro.producto = flu.producto)
left join especies esp on (esp.especie = pro.especie)
order by flu.zona, dtr.cod_fundo, flu.producto, flu.destino, sup.codigo");
$tansporCollect = collect();
$tansporCollectsinCosto = collect();
foreach ($var as $f) {
if($f->codigo != null){
if($f->especie == 1){
$a = 0.177548*$f->dist_no_pavimento;
$b = 0.0746*$f->dist_pavimento;
$c = 0.0333*$f->peaje;
$costoFundo = ($a + $b + 1.1191 + 0.399 + $c)*$f->sup_ha;
}
else{
$a = 0.1652*$f->dist_no_pavimento;
$b = 0.0694*$f->dist_pavimento;
$c = 0.0357*$f->peaje;
$costoFundo = ($a + $b + 1.0421 + 0.599 + $c)*$f->sup_ha;
}
$tansporC =[
'zona' => $f->zona,
'destino' => $f->destino,
'producto' => $f->producto,
'especie' => $f->especie,
'costo' => $costoFundo
];
$tansporCollect->push($tansporC);
$tansporsinCosto = [
'zona' => $f->zona,
'destino' => $f->destino,
'producto' => $f->producto,
'especie' => $f->especie,
];
$tansporCollectsinCosto->push($tansporsinCosto);
}
}
$zonas = $tansporCollect->pluck('zona')->unique();
$destinos = $tansporCollect->pluck('destino')->unique();
$especies = $tansporCollect->pluck('especie')->unique();
$transporCollectUnique = $tansporCollectsinCosto->unique();
foreach($zonas as $zon){
$costoZona = $tansporCollect->where('zona',$zon);
foreach($destinos as $destin){
$costoDestino = $costoZona->where('destino',$destin);
foreach($especies as $espec){
$costoEspecie = $costoDestino->where('especie',$espec)->avg('costo');
/*HERE IM CALL OTHER FUNCTION */
$this->reemplazaCostoZona($zon, $destin, $espec, $costoEspecie, $transporCollectUnique);
}
}
}
}
I'm with laravel 5.8
You are not using the where function of collections correctly. For collections you need the following:
$productos = $transporCollect->where('zona', $zona)
->where('destino', $destino)
->where('especie',$especie)
->pluck('producto');
Hope that helps!

Laravel - Get data based on date range using eloquent

Heei, I want to show data according to daterange. Specifically data on this day and 6 days to go. Here's my code now.
Controller
$hari = [];
for ($i=0; $i < 6; $i++)
{
$hari[] = date("Y M d") + $i;
}
$booking_room = jadwal_meeting::whereBetween('tanggal', [$hari, $hari + 6])->get();
return view('homepage')->with($booking_room);
Note: 'tanggal' is a field on table.
But I just get error like this
Unsupported operand types
: $booking_room = jadwal_meeting::whereBetween('tanggal', [$hari, $hari + 6])->get();
What's wrong with my code, anyone can help me please :)
Since $hari is an array, you have to use something like this:
$booking_room = jadwal_meeting::whereBetween('tanggal', [$hari[0], $hari[5]])->get();
Or more general:
$booking_room = jadwal_meeting::whereBetween('tanggal', [$hari[0], end($hari)])->get();
Try this code it will help you.
$from = '2018-04-12';
$to = date('Y-m-d', strtotime($from. ' + 6 days'));
$reservations = Reservation::whereBetween('tanggal', [$from, $to])
->get();
Thanks,

Php Generate random number without repeat

$C = $_POST['Cc'];
$X = $_POST['X'];
$CX = $_POST['Cc'] . $_POST['X'];
$NC = preg_replace_callback("/x/" ,function() {return rand(0,9);}, $CX);
$New = $NC ;
$NNew = str_repeat($New,10);
echo $NNew;
what's wrong when i output it , it gives me the same number How to make It Don't Give me the same Numbers ??
It's basically you are not changing the seed for the rand method. Each time it's getting same seed and generating same number.
Read this PHP manual : http://php.net/manual/en/function.srand.php
Check the code snippet below:
<?php
// seed with microseconds
function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return $sec + $usec * 1000000;
}
srand(make_seed());
$randval = rand(0,9);
echo $randval;
?>
Or you can use mt_rand() which is seeded differently on each execution.

laravel get items from two separate table and merge the result with pagination

I have two tables, one of them is "posts" and the other one is "notifications". I want to show the users a list of posts and notifications with pagination. how can I do that efficiently?
I have this code that works fine but it is not efficient because I get all the data and then slice them. I want to do the pagination, using MYSQL
public function list_post_notification(Request $request , $page_number = 1 , $per_page=10 , $brand_id = null ){
$brand =$this->brandRepository->getMagazinBrand() ;
$posts = $brand->posts()->orderBy('posts.created_at' , 'desc')->take($page_number * $per_page) ;
$notifs = $brand->notifications()->orderBy('notifications.created_at' , 'desc')->take($page_number * $per_page) ;
$result = [] ;
foreach ($posts->get() as $k=>$v){
$item = [
'type'=>'post' ,
'uuid'=>$v->uuid,
'title'=>$v->title,
'created_at'=>strtotime($v->created_at),
'creator'=>$v->brand->fa_name,
'brand_id'=>$v->brand->id,
];
$result[$item['created_at']] =$item ;
}
foreach ($notifs->get() as $k=>$v){
$item = [
'type'=>'notification' ,
'uuid'=>$v->uuid,
'title'=>$v->title,
'created_at'=>strtotime($v->created_at),
'creator'=>$v->brand->fa_name,
'brand_id'=>$v->brand->id,
];
$result[$item['created_at']] =$item ;
}
krsort($result) ;
$start = 0 ;
if ($page_number > 1)
$start = ($page_number -1 ) * $per_page ;
return response()
->json(array_slice($result , $start , $per_page)) ;
}
You can merge all your items and create one Collection.
$resultCollection = collect($result).
Than use forPage method.

Timepicker that removes times as they're selected (ajax)

I'm building a booking form for a moving business that uses a calendar combined with a start and end time. I built the timepicker with Formidable Pro, and it allows me to check "unique" on time fields which automatically removes them on the selected date. However it doesn't automatically remove the times from within the range between start and end times (ie: if someone chooses to rent a truck from 1am-3am I need 1am,2am,and 3am to be removed from future options but right now it only removes 1am and 3am) . I need to write ajax to remove the in-between times from the options. I'm not sure where to begin. This is the current ajax_time_ options function. Any push in the right direction would be appreciated.
function ajax_time_options(){
global $frmpro_settings, $frmdb, $wpdb;
//posted vars = $time_field, $date_field, $step, $start, $end, $date, $clock
extract($_POST);
$time_key = str_replace('field_', '', $time_field);
$date_key = str_replace('field_', '', $date_field);
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', trim($date)))
$date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
$date_entries = FrmEntryMeta::getEntryIds("fi.field_key='$date_key' and meta_value='$date'");
$opts = array('' => '');
$time = strtotime($start);
$end = strtotime($end);
$step = explode(':', $step);
$step = (isset($step[1])) ? ($step[0] * 3600 + $step[1] * 60) : ($step[0] * 60);
$format = ($clock) ? 'H:i' : 'h:i A';
while($time <= $end){
$opts[date($format, $time)] = date($format, $time);
$time += $step;
}
if($date_entries and !empty($date_entries)){
$used_times = $wpdb->get_col("SELECT meta_value FROM $frmdb->entry_metas it LEFT JOIN $frmdb->fields fi ON (it.field_id = fi.id) WHERE fi.field_key='$time_key' and it.item_id in (". implode(',', $date_entries).")");
if($used_times and !empty($used_times)){
$number_allowed = apply_filters('frm_allowed_time_count', 1, $time_key, $date_key);
$count = array();
foreach($used_times as $used){
if(!isset($opts[$used]))
continue;
if(!isset($count[$used]))
$count[$used] = 0;
$count[$used]++;
if((int)$count[$used] >= $number_allowed)
unset($opts[$used]);
}
unset($count);
}
}
echo json_encode($opts);
die();
}

Resources