/*
* Created on Sep 26, 2006
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
include_once 'dataset.php';
include_once 'global.php';
include_once 'modules.mailer.php';
include_once 'modules.orders.php';
include_once 'modules.products.php';
include_once 'modules.upsOnline.php';
include_once 'modules.new_cart_v2.php';
include_once 'modules.address.php';
include_once 'modules.utils.php';
include_once 'modules.googlecheckout.php';
class shipping_v2
{
public $zones;
public $verbose = '';
public $max_ships_in_days_val = array();
function shipping_carrier_from_shipping_type($order_id)
{
global $pdo_db1;
$shipping_infos = $pdo_db1->pquery(
" SELECT
orders.website,
orders.shipping_type,
shipping_types.carrier,
(SELECT address.state from address where address.id=orders.shipping_address_id) as state
FROM
orders
INNER JOIN shipping_types ON orders.shipping_type = shipping_types.id
WHERE
orders.id = '" .
$order_id .
"'
"
);
$shipping_info = $shipping_infos[0];
$carrier_id = $shipping_info['carrier'];
if (
$shipping_info['website'] == '2' ||
$shipping_info['website'] == '3' ||
$shipping_info['website'] == '5' ||
$shipping_info['website'] == '6' ||
$shipping_info['website'] == '7' ||
$shipping_info['website'] == '21' ||
$shipping_info['website'] == '24' ||
$shipping_info['website'] == '26'
) {
// over-write ARTTOFRAMES
$carrier_id = '2'; // FEDEX
$state = ['NY', 'PA', 'CT', 'NH', 'NJ'];
if (
($shipping_info['website'] == '2' ||
$shipping_info['website'] == '3') &&
in_array($shipping_info['state'], $state)
) {
//SAMA DAY
$carrier_id = '1'; // USPS SAME DAY
}
if ($shipping_info['shipping_type'] == '28') {
//SAMA DAY
$carrier_id = '3'; // USPS SAME DAY
}
}
return $carrier_id;
}
function update_status($order_id, $status, $fields)
{
global $pdo_db1;
$data1 = new dataset();
$data1->db_connect();
//print_r($fields);
$fields_ship = [];
$fields_ship['order_id'] = $order_id;
$fields_ship['status_id'] = $status;
$fields_ship['price'] = $fields['price'];
$fields_ship['cost_price'] = $fields['cost_price'];
$fields_ship['fld1'] = $fields['carrier'];
$fields_ship['fld2'] = $fields['tracking_number'];
$shipping_info_id = $data1->add_record(
'shipping_history',
$fields_ship
);
$fields_ord = [];
$fields_ord['shipping_status'] = $status;
$fields_ord['shipping_info_id'] = $shipping_info_id;
$fields_ord['shipping_cost'] = $fields['price'];
$o = new orders();
$res = $o->update_order($order_id, $fields_ord);
if ($res === false) {
return false;
} else {
return $res;
}
}
function shipping_info($shipping_info_id)
{
global $pdo_db1;
$data1 = new dataset();
$data1->db_connect();
//$res = $data1->get_record("shipping_history", "id", $shipping_info_id);
$res = $pdo_db1->pquery(
"SELECT * FROM shipping_history WHERE id = '" .
$shipping_info_id .
"' ",
'FETCH_BOTH'
);
if ($pdo_db1->pdo_num_rows($res) > 0) {
$info = $res[0];
return $info;
} else {
return false;
}
}
function order_shipped(
$order_id,
$status_code,
$user_id,
$tracking_num,
$carrier,
$shipping_price,
$force_email = false
) {
global $pdo_db1;
$o = new orders();
$order_info = $o->order_info($order_id);
$fields = [];
$fields['price'] = $order_info['shipping_cost'];
$fields['carrier'] = $carrier;
$fields['cost_price'] = $shipping_price;
$fields['tracking_number'] = $tracking_num;
$order_shipping_info = $o->shipping_info($order_id);
$add_traking = 'yes';
if (isset($order_shipping_info) && $order_shipping_info != '') {
foreach ($order_shipping_info as $key => $shipping_info) {
if ($shipping_info['tracking_number'] == $tracking_num) {
// commented add tracking because the orders.ship_date is updating Null in orders DB table.
// Update on 2021/03/10 Farhan Qazi
//$add_traking = 'no';
// echo '1';
} else {
// echo '2';
}
}
}
if ($add_traking == 'no') {
return false;
} else {
$res = $this->update_status($order_id, $status_code, $fields);
$fields = [];
if (
$order_info['ship_date'] == '0000-00-00' ||
$order_info['ship_date'] == '' ||
$order_info['ship_date'] == null
) {
$fields['ship_date'] = date('Y-m-d');
$d = new DataSet();
$d->update_record('orders', $fields, 'id', $order_id);
} else {
echo '
Ship date already assign
';
}
if ($order_info['payment_type'] != '2' || $force_email == true) {
//check if orders.admin_status = 15 then ignore shipping email
$allow_to_send_shipping_email = 1; //send
if ($order_info['admin_status'] == 15) {
//Ready for Pickup / Waiting for Pickup
$allow_to_send_shipping_email = 0; //not send
}
if ($allow_to_send_shipping_email) {
/*new code: need to confirm*/
//$sqlSelCarrier = "SELECT tracking_number, carrier_id FROM `end_of_day` WHERE `order_id` LIKE '$order_id' LIMIT 1";//commented on 20-01-2016 ssd
/*$sqlSelCarrier = "SELECT end_of_day.tracking_number, end_of_day.carrier_id, end_of_day.order_id, orders.website FROM `end_of_day` INNER JOIN orders ON orders.id = end_of_day.order_id WHERE `order_id` LIKE '$order_id' AND orders.website = '2' ORDER BY end_of_day.id DESC LIMIT 1 ";*/
//Query changed date 24th Jan, 2017
//Task: on repalcemtn tracking email the custome got the original tracking information
//damages sent with an additional "a" or "A"
//Exclude void tracking numbers as well and only get valid tracking number - 19Apr2022
$sqlSelCarrier = "SELECT end_of_day.tracking_number, end_of_day.carrier_id, end_of_day.order_id, orders.website FROM `end_of_day` INNER JOIN orders ON orders.id = end_of_day.order_id WHERE end_of_day.order_id = '$order_id' AND orders.website = '2' AND end_of_day.void = '0' ORDER BY end_of_day.id DESC LIMIT 1";
$resSelCarrier = $pdo_db1->pquery($sqlSelCarrier);
if ($pdo_db1->pdo_num_rows($resSelCarrier) > 0) {
foreach ($resSelCarrier as $rowSelCarrier) {
$carrier = $rowSelCarrier['carrier_id'];
$tracking_num = $rowSelCarrier['tracking_number'];
}
}
/*new code: need to confirm*/
$this->email_shipping_notification(
$order_id,
$carrier,
$tracking_num
);
} //if($allow_to_send_shipping_email)
}
if ($order_info['payment_type'] == '2') {
$g = new googlecheckout();
$g->deliver_order($order_id, $carrier, $tracking_num);
}
//echo $add_traking . ' = ' ;
//exit;
return true;
}
}
function email_shipping_notification(
$order_id,
$carrier,
$tracking_num = ''
) {
global $pdo_db1;
$a = new art();
$isdamage_order = 0;
/******************code added on 11march 2016 ssd*******************/
$mailer = new mailer();
$a = new address();
$o = new orders();
$p = new products();
$carriers = $this->list_carriers();
$order_info = $o->order_info($order_id);
$date_array = $o->getDeliveryDateWithLabel($order_id);
$isdamage_order = $order_info['damaged'];
$product_weight = $o->product_weight(
$order_id,
'weight',
$isdamage_order
);
$due_date_array = explode('-', $order_info['due_date']);
$pdo_db1->pquery('SET character_set_results=utf8');
$pdo_db1->pquery('SET NAMES utf8');
// DD/MM/YY an in database it store as YY-MM-DD
//$due_date = $due_date_array[2].'/'.$due_date_array[1].'/'.$due_date_array[0];
// now changes to MM/DD/YY -- 9 MAY 17 -
$due_date =
$due_date_array[1] .
'/' .
$due_date_array[2] .
'/' .
$due_date_array[0];
$shipping_types = $this->list_shipping_types();
$shipping_info = $a->address_info($order_info['shipping_address_id']);
//$to = $order_info['user_info']['username'];
// Updated the below code set the username if array exist on 2024-07-24
if(isset($order_info['user_info']['username']) && !empty($order_info['user_info']['username'])){
$to = $order_info['user_info']['username'];
}
//$to = 'atf_programmers@arttoframes.com';
#################
//START - To Check Is Tracking Number is Valid and Not Voided (i.e. end_of_day.void = '1')... If voided then stop shipping notification... 19Apr2022
if (strlen(trim($tracking_num)) > 0) {
$is_tracking_num_voided = $p->specific_select(
'end_of_day',
'tracking_number',
$tracking_num,
'void'
);
if ($is_tracking_num_voided == '1') {
$tracking_num = ''; //Made tracking number... In this case following if($tracking_num == '') will take care of valid tracking number
}
}
//End - To Check Is Tracking Number is Valid and Not Voided (i.e. end_of_day.void = '1')... If voided then stop shipping notification... 19Apr2022
#################
if ($tracking_num == '') {
//$tracking_num = $p->specific_select("end_of_day","order_id",$order_id,"tracking_number");
$sqlSelTrackNo = "SELECT end_of_day.tracking_number FROM `end_of_day` INNER JOIN orders ON orders.id = end_of_day.order_id WHERE end_of_day.order_id = '$order_id' AND orders.website = '2' AND end_of_day.void = '0' ORDER BY end_of_day.id DESC LIMIT 1";
$resSelTrackNo = $pdo_db1->pquery($sqlSelTrackNo);
if ($pdo_db1->pdo_num_rows($resSelTrackNo) > 0) {
$rowSelTrackNo = $resSelTrackNo[0];
$tracking_num = $rowSelTrackNo['tracking_number'];
} else {
$tracking_num = $p->specific_select(
'end_of_day',
'order_id',
$order_id,
'tracking_number',
" AND void = '0' ORDER BY id DESC"
);
}
}
#################
//START - If $tracking_num == '' / empty then stop shipping notification... 19Apr2022
if (strlen(trim($tracking_num)) == 0 || $tracking_num == '') {
return true;
}
//End - If $tracking_num == '' / empty then stop shipping notification... 19Apr2022
#################
$estimated_delivery_date = '';
$estimated_delivery_date = $p->specific_select(
'orders',
'id',
$order_id,
'estimated_delivery_date'
);
$style_date = '';
if (
$estimated_delivery_date == '' or
$estimated_delivery_date == '0000-00-00 00:00:00'
) {
$style_date = 'display: none;';
}
$allow_send_email = $p->specific_select(
'website',
'id',
$order_info['website'],
'allow_send_email'
); //allow_send_email having values 0,1
/****************allow_send_email code added on 19Jan18 by ssd *********************/
###########START DT: 11Oct2019 SSG - website.shipped_to_email###########
/****************shipped_to_email code added on 11Oct19 by ssg *********************/
$shipped_to_email = $p->specific_select(
'website',
'id',
$order_info['website'],
'shipped_to_email'
); //shipped_to_email addresses
if ($allow_send_email == 0 && strlen(trim($shipped_to_email)) > 0) {
$allow_send_email = 1; //allow to send email to as per field value website.shipped_to_email
$to = $shipped_to_email; //Email to website.shipped_to_email
}
###########END DT: 11Oct2019 SSG - website.shipped_to_email###########
$arry = get_time_on_pickup_conf_new();
$arry1 = $arry[1];
if ($allow_send_email == 1) {
//$allow_send_email == 1 then send email based on block
if ($order_info['website'] == '3') {
//commented the code as requirement of client on date - 19 Oct 2015
//AMAZON arttoframe
/*$subject = "Your Amazon.com order #".$order_info['third_party_order_number']." with ArtToFrames #$order_id has shiped !";
$body = "Hello " . $order_info["user_info"]["firstname"] . ",\n" .
" Your amazon order #".$order_info['third_party_order_number']." (ArtToFrames #$order_id ) has shipped." .
"\n";
# $body.= " It has been shipped with " . $carriers[$carrier]["carrier_name"] . ". \n";
if($carriers[$carrier]["tracking_num"]=="1"){
$body.=" The tracking number is $tracking_num" . "." .
"\n";
}
$body.=
" Thank you for choosing ArtToFrames at amazon for your Art and Framing needs.".
" If you have any questions please call 1-718-788-6200
\n";
$body.=
"Shipping Department ".
"ArtToFrame";
$headers = '' ; // "From: shipping@arttoframes.com" . "\r\n" . "Bcc: shipping@arttoframes.com";
$email_id = $mailer->send_email($to, $subject, $body, $headers,"","","amazon_shipping");*/
} elseif ($order_info['website'] == '24') {
//AMAZON WindowPix
$subject =
'Your Amazon.com order #' .
$order_info['third_party_order_number'] .
" with WindowPix #$order_id has shiped !";
$body =
'Hello ' .
$order_info['user_info']['firstname'] .
",\n" .
' Your amazon order #' .
$order_info['third_party_order_number'] .
" (WindowPix #$order_id ) has shipped." .
"\n";
# $body.= " It has been shipped with " . $carriers[$carrier]["carrier_name"] . ". \n";
if ($carriers[$carrier]['tracking_num'] == '1') {
$body .=
" The tracking number is $tracking_num" .
'.' .
"\n";
}
$body .=
' Thank you for choosing WindowPix at Amazon.' .
' If you have any questions please call ' .
$arry1 .
"
\n";
$body .= 'WindowPix Shipping Department ';
$headers = ''; // "From: shipping@arttoframes.com" . "\r\n" . "Bcc: shipping@arttoframes.com";
$email_id = $mailer->send_email(
$to,
$subject,
$body,
$headers,
'',
'',
'amazon_shipping',
$order_id
);
} else {
$subject = "Your ArtToFrames.com order #$order_id has shipped!";
$headers =
'From: shipping@arttoframes.com' .
"\r\n" .
'Bcc: shipping@arttoframes.com';
$userfirstname = $order_info['user_info']['firstname'];
$CarrierName = $trackYourOrder = $url = $style = '';
//This new function implemented to get dynamic url from db table as on 15Apr2022
$url = $this->get_shipping_tracking_url(
$tracking_num,
$order_id,
'url_only'
);
$CarrierName =
' Your order was shipped with ' .
$carriers[$carrier]['carrier_name'] .
" tracking $tracking_num";
//START=> code added if anything wrong with carrier id or user id by SSD
$end_of_day_user_id = $p->specific_select(
'end_of_day',
'order_id',
$order_id,
'user_id'
);
if ($end_of_day_user_id == '' or $end_of_day_user_id == null) {
$url = 'https://www.google.com/search?q=' . $tracking_num;
$CarrierName =
' Your order was shipped with ' .
$carriers[$carrier]['carrier_name'] .
" tracking $tracking_num";
}
//END=> code added if anything wrong with carrier id or user id by SSD
$order_items = $order_info['order_items'];
$total_qty = 0;
if ($isdamage_order) {
foreach ($order_items as $key => $item) {
if ($item['order_item_details_new'][0]['damage']) {
$qty = $item['qty'];
$total_qty = $qty + $total_qty;
}
}
} else {
foreach ($order_items as $key => $item) {
$qty = $item['qty'];
$total_qty = $qty + $total_qty;
}
}
$sql_footer_banners = $pdo_db1->pquery(
'SELECT * FROM `email_template_footer_banners` WHERE in_stock = 1 ORDER BY rand() limit 1'
);
foreach ($sql_footer_banners as $row_img) {
$banner_title = $row_img['banner_title'];
$banner_url = $row_img['banner_image_link'];
$banner_hyperlink = $row_img['banner_hyperlink'];
}
/*$body='
.'/images_2014/shipping-header.png)
DEAR '. strtoupper($order_info["user_info"]["firstname"]).'
YOUR ORDER IS BEING SHIPPED.
SHIPPING DETAILS
| TRACKING NUMBER: | '.$tracking_num.' |
| DELIVERY ADDRESS: | '.$shipping_info["name"].' '.$shipping_info["address"].' '.$shipping_info["address2"].' '.$shipping_info["address3"].' '.$shipping_info["city"] . " " . $shipping_info["state"] . ", " . $shipping_info["zip"].' Phone #'.$shipping_info["phone"].' '.$shipping_info["country"].' |
| SHIP METHOD: | '.$shipping_types[$order_info["shipping_type"]]["name"].' |
| PARCEL QTY: | '.$total_qty.' |
| TOTAL WEIGHT: | '.$product_weight.' lbs |
| ESTIMATED TIME: | '.$due_date.' |
| ORDER NUMBER: | '.$order_id.' |
.'/images_2014/delivery.png?v=2)
Become a part of our family and share your finished product on our Facebook page!
https://www.facebook.com/ArtToFramesIf you have any questions concerning your art,please call our customer service department at 718.788.6200.
Many Thanks.
'.$o->getCustomerServiceUserName($order_id).'
Customer service manager
.'/images_2014/mobile/logo2.png)
Mail: cs@arttoframes.com
Phone #: 718.788.6200
770 5TH AVE
BROOKLYN, NY 11232
UNITED STATES