View file File name : export-giftcard.php Content :<?php include("../include/config.php"); include("../include/functions.php"); if($_REQUEST['exportExcel']=='yes'){ $userlocationWhere=''; $user_type = getFieldWhere('user_type', 'tbl_admin', 'id', $_SESSION['sess_admin_id']); $user_location=getFieldWhere('location', 'tbl_admin', 'id', $_SESSION['sess_admin_id']); $user_location=implode("','",explode(",",$user_location)); //echo "select group_concat(distinct zip) as zip from tbl_store_zip where state in ('$user_location') and zip!=''"; $userziparr=array(); $userzip=$obj->query("select distinct(zip) as zip from tbl_store_zip where state in ('$user_location') and zip!=''"); while($resuserZip=$obj->fetchNextObject($userzip)){ array_push($userziparr,$resuserZip->zip); } $userLocationZip=implode(',',$userziparr); if($user_location!=''){ $userlocationWhere='and tbl_order.ship_pincode in('.$userLocationZip.')'; } $where = ''; if (trim($_REQUEST['search_order_id']) != '') { $name = trim($_REQUEST['search_order_id']); $where .= " and tbl_order.id='" . $name . "'"; } if (trim($_REQUEST['search_user_id']) != '') { $name = trim($_REQUEST['search_user_id']); $where .= " and tbl_order.user_id='" . $name . "'"; } if (trim($_REQUEST['search_email']) != '') { $name = trim($_REQUEST['search_email']); $where .= " and ship_email like '%$name%' "; } if (trim($_REQUEST['search_storename']) != '') { $name = trim($_REQUEST['search_storename']); $where .= " and tbl_order_itmes.storeid like '%$name%'"; } if (trim($_REQUEST['search_device']) != '') { $name = trim($_REQUEST['search_device']); $where .= " and tbl_order.order_via='" . $name . "'"; } if (trim($_REQUEST['search_from_date']) != '' && trim($_REQUEST['search_to_date']) != '') { $where .= " and tbl_order.order_date>='" . trim($_REQUEST['search_from_date']) . "' and tbl_order.order_date<='" . trim($_REQUEST['search_to_date']) . "' "; } $order_by=' tbl_order.id '; $order_by2='desc'; $sql=$obj->Query("select tbl_order_itmes.storeid,tbl_order_itmes.section,tbl_order.id,tbl_order.ship_email,tbl_order.user_id,tbl_order.order_via,tbl_order.tax_value,tbl_order.delivery_type,tbl_order.order_type,tbl_order.total_amount,tbl_order.ship_type,tbl_order.order_date,tbl_order.usps_expected_delivery,tbl_order.tracking_no,tbl_order.payment_method,tbl_order.order_status,tbl_order.payment_status,tbl_order.delivery_note,tbl_order.sub_id,ship_fname,ship_lname,ship_house_no,ship_street,ship_complex,ship_landmark,ship_pincode,ship_area,ship_state,ship_city_id,ship_mobile,tbl_order.deliverby,tbl_order.is_send_to_vendor,tbl_order.vendor_sync_comments from $tbl_order inner join tbl_order_itmes on tbl_order.id=tbl_order_itmes.order_id where 1=1 $userlocationWhere $where order by $order_by $order_by2 ",$debug=-1); $csvData=''; $csvData.="Order ID, User Id, User Email,Card Name,Sender,Receiver,Receiver Email,Delivery Date,Store Details,Email Sent,Wallet Added,Total Amount,Order Date, Order Via, Order Status,Payment Status,Customer Details"; $csvData.="\n\r"; $reccnt=$obj->numRows($sql); if($reccnt>0){ $count=1; while($data=$obj->fetchNextObject($sql)) { $sql_gc = $obj->query("select * from $tbl_giftcard_orders gc JOIN $tbl_giftcard_order_emails gce ON gc.id = gce.giftcard_order_id where gc.order_id=".$data->id); $record_gc = $obj->numRows($sql_gc); while($result_gc = $obj->fetchNextObject($sql_gc)) { $address = ''; if($data->ship_full_address==''){ $address = $data->ship_house_no . "; " . $data->ship_street . "; " . $data->ship_complex . "; " . $data->ship_area . " " . $data->ship_city_id . " " . $data->ship_state . "; " . $data->ship_pincode; } else { $address = $data->ship_full_address. "; ".$data->ship_complex ."; " . $data->ship_pincode; } $csvData.= stripslashes($data->id).","; $csvData.= stripslashes($data->user_id).","; $csvData.= stripslashes($data->ship_email).","; $csvData.= ucfirst(stripslashes($result_gc->card_type))." ".ucfirst(stripslashes($result_gc->card_cat)).","; $csvData.= stripslashes($result_gc->sender).","; $csvData.= stripslashes($result_gc->receiver).","; $csvData.= stripslashes($result_gc->receiver_email).","; $csvData.= date('d-m-Y', strtotime($result_gc->delivery_date)).","; $csvData.= str_replace(",",";",stripslashes($result_gc->storename))."-".str_replace(",",";",stripslashes($result_gc->store_location)).","; $csvData.= ($result_gc->email_flag == 1 ? 'Yes' : 'No').","; $csvData.= ($result_gc->wallet_flag == 1 ? 'Yes' : 'No').","; $csvData.= $website_currency_symbol . " " . number_format($data->total_amount, 2).","; $csvData.= date('d M Y H:i', strtotime($data->order_date)).","; $csvData.= stripslashes($data->order_via).","; $csvData.= getField('order_status', $tbl_order_status, $data->order_status).","; $csvData.= ($data->payment_status == 1 ? 'Successfull' : 'Unsuccessfull').","; $csvData.= ucwords($data->ship_fname . " " . $data->ship_lname).';'.$data->ship_mobile.";".$address.","; $csvData.="\n\r"; $count++; } } } header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/csv"); header("Content-Disposition: attachment; filename=GiftCard-Report-".date("dMY_H:i").".csv"); echo $csvData; exit; header("location:".$_SERVER['HTTP_REFERER']); exit(); } ?>