Ejemplo n.º 1
0
 function closeFedEx($close_date = '', $report_only = false, $report_type = 'MANIFEST')
 {
     global $messageStack;
     $today = date('Y-m-d');
     if (!$close_date) {
         $close_date = $today;
     }
     $report_only = $close_date == $today ? false : true;
     $date = explode('-', $close_date);
     $error = false;
     foreach (array('FDXG', 'FDXE') as $code) {
         $strXML = $this->FormatFedExCloseRequest($code, $close_date, $report_only);
         //echo 'strXML = ' . htmlspecialchars($strXML) . '<br /><br />';
         $SubmitXML = GetXMLString($strXML, $this->rate_url, "POST");
         // Check for XML request errors
         if ($SubmitXML['result'] == 'error') {
             $messageStack->add(SHIPPING_FEDEX_CURL_ERROR . $SubmitXML['message'], 'error');
             $error = true;
             continue;
         }
         $ResponseXML = $SubmitXML['xmlString'];
         //echo 'ResponseXML = ' . htmlspecialchars($ResponseXML) . '<br /><br />';
         // Check for errors returned from FedEx
         $XMLFail = GetNodeData($ResponseXML, 'Error:Code');
         if ($XMLFail) {
             // fetch the error code
             $messageStack->add('FedEx service: ' . $code . ' Close Error # ' . $XMLFail . ' - ' . GetNodeData($ResponseXML, 'Error:Message'), 'caution');
             $error = true;
             continue;
         }
         // Fetch the FedEx reports
         $file_path = DIR_FS_MY_FILES . $_SESSION['company'] . '/shipping/reports/' . $this->code . '/' . $date[0] . '/' . $date[1] . '/';
         validate_path($file_path);
         //echo 'file_path = ' . ($file_path) . '<br />';
         $file_name = $date[2] . '-' . GetNodeData($ResponseXML, 'Manifest:FileName') . '.txt';
         //echo 'file_name = ' . ($file_name) . '<br />';
         $mwReport = base64_decode(GetNodeData($ResponseXML, 'MultiweightReport'));
         $closeReport = base64_decode(GetNodeData($ResponseXML, 'Manifest:File'));
         //echo 'close report = ' . $closeReport . '<br />';
         $codReport = base64_decode(GetNodeData($ResponseXML, 'CODReport'));
         //			$hazMatReport = base64_decode(GetNodeData($ResponseXML, 'HazMatCertificate'));
         if (!($handle = fopen($file_path . $file_name, 'w'))) {
             echo 'Cannot open file (' . $file_path . $file_name . ')';
             $error = true;
             continue;
         }
         if (fwrite($handle, $closeReport) === false) {
             $messageStack->add('Cannot write close report to file (' . $file_path . $file_name . ')', 'error');
             $error = true;
             continue;
         }
         if (fwrite($handle, $mwReport) === false) {
             $messageStack->add('Cannot write multi-weight report to file (' . $file_path . $file_name . ')', 'error');
             $error = true;
             continue;
         }
         if (fwrite($handle, $codReport) === false) {
             $messageStack->add('Cannot write COD report to file (' . $file_path . $file_name . ')', 'error');
             $error = true;
             continue;
         }
         /*
         			if (fwrite($handle, $hazMatReport) === false) {
         				$messageStack->add('Cannot write Hazmat report to file (' . $file_path . $file_name . ')','error');
         				$error = true;
         				continue;
         			}
         */
         fclose($handle);
     }
     if (!$error) {
         $messageStack->add('Successfully closed the FedEx shipments for today.', 'success');
     }
     return true;
 }
Ejemplo n.º 2
0
function GetPackageArray($SearchXML, $Container, $TagsToFind)
{
    $arrXML = false;
    $Container = strtolower($Container);
    $StartTag = strpos(strtolower($SearchXML), '<' . $Container . '>');
    while ($StartTag) {
        $EndTag = strpos(strtolower($SearchXML), '</' . $Container . '>');
        $tempXML = substr($SearchXML, $StartTag, $EndTag - $StartTag);
        // Work with just the beginning instance
        $tagArray = array();
        foreach ($TagsToFind as $key => $value) {
            $tagArray[$key] = GetNodeData($tempXML, $value);
        }
        $arrXML[] = $tagArray;
        $SearchXML = substr($SearchXML, $EndTag + strlen('</' . $Container . '>') - 1);
        // Trim the first instance to see if there are more
        $StartTag = strpos(strtolower($SearchXML), '<' . $Container . '>');
    }
    return $arrXML;
}
Ejemplo n.º 3
0
 function deleteLabel($shipment_id = '')
 {
     global $db, $messageStack;
     if (!$shipment_id) {
         $messageStack->add('Cannot delete shipment, shipment ID was not provided!', 'error');
         return false;
     }
     if ($this->tracking_number) {
         $tracking_number = $this->tracking_number;
     } else {
         $shipments = $db->Execute("select ship_date, tracking_id from " . TABLE_SHIPPING_LOG . " where shipment_id = " . $shipment_id);
         $tracking_number = $shipments->fields['tracking_id'];
     }
     $strXML = $this->FormatUPSDeleteRequest($tracking_number);
     $this->labelDelRequest = $strXML;
     //echo 'Delete Request xmlString = ' . htmlspecialchars($strXML) . '<br />';
     $url = MODULE_SHIPPING_UPS_TEST_MODE == 'Test' ? MODULE_SHIPPING_UPS_VOID_SHIPMENT_TEST : MODULE_SHIPPING_UPS_VOID_SHIPMENT;
     $SubmitXML = GetXMLString($strXML, $url, "POST");
     $this->labelDelResponse = $SubmitXML['xmlString'];
     //echo 'Delete Request response string = ' . htmlspecialchars($SubmitXML['xmlString']) . '<br />';
     // Check for XML request errors
     if ($SubmitXML['result'] == 'error') {
         $messageStack->add(SHIPPING_UPS_CURL_ERROR . $SubmitXML['message'], 'error');
         return false;
     }
     $ResponseXML = $SubmitXML['xmlString'];
     $XMLFail = GetNodeData($ResponseXML, 'VoidShipmentResponse:Response:Error:ErrorCode');
     // Check for errors returned from UPS
     $XMLWarn = GetNodeData($ResponseXML, 'VoidShipmentResponse:Response:Error:ErrorSeverity');
     // Check for warnings returned from UPS (process continues)
     if ($XMLFail && $XMLWarn == 'Warning') {
         // soft error, report it and continue
         $messageStack->add('UPS Label Delete Warning # ' . $XMLFail . ' - ' . GetNodeData($ResponseXML, 'VoidShipmentResponse:Response:Error:ErrorDescription'), 'caution');
     } elseif ($XMLFail && $XMLWarn != 'Warning') {
         // hard error - return with bad news
         $messageStack->add('UPS Label Delete Error # ' . $XMLFail . ' - ' . GetNodeData($ResponseXML, 'VoidShipmentResponse:Response:Error:ErrorDescription'), 'error');
         return false;
     }
     // delete the label file
     $date = explode('-', $shipments->fields['ship_date']);
     $file_path = DIR_FS_MY_FILES . $_SESSION['company'] . '/shipping/labels/' . $this->code . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
     if (file_exists($file_path . $shipments->fields['tracking_id'] . '.lpt')) {
         $file_name = $shipments->fields['tracking_id'] . '.lpt';
     } elseif (file_exists($file_path . $shipments->fields['tracking_id'] . '.gif')) {
         $file_name = $shipments->fields['tracking_id'] . '.gif';
     } else {
         $file_name = false;
         // file does not exist, skip
     }
     if ($file_name) {
         if (!unlink($file_path . $file_name)) {
             $messageStack->add_session('Trouble deleting label file (' . $file_path . $file_name . ')', 'caution');
         }
     }
     // if we are here the delete was successful, the lack of an error indicates success
     $messageStack->add_session('Successfully deleted the UPS shipping label. Tracking # ' . $tracking_number, 'success');
     return true;
 }
Ejemplo n.º 4
0
 function GetUSPSRateArray($SearchXML, $packageID)
 {
     $arrXML = false;
     $StartTag = strpos($SearchXML, '<Package ID="' . $packageID . '">');
     $EndTag = strpos($SearchXML, '</Package>', $StartTag);
     $pkgXML = substr($SearchXML, $StartTag, $EndTag - $StartTag);
     // just have the package ID # return string only
     while (true) {
         $StartTag = strpos($pkgXML, '<Postage>');
         if ($StartTag === false) {
             break;
         }
         $service = GetNodeData($pkgXML, 'MailService');
         $rate = GetNodeData($pkgXML, 'Rate');
         foreach ($this->USPSRateCodes as $key => $value) {
             if ($service == $key) {
                 $arrXML[$this->code][$value]['book'] = $rate;
                 $arrXML[$this->code][$value]['quote'] = $rate;
                 $arrXML[$this->code][$value]['cost'] = $rate;
                 $arrXML[$this->code][$value]['note'] = '';
             }
         }
         $EndTag = strpos($pkgXML, '</Postage>', $StartTag);
         $pkgXML = substr($pkgXML, $EndTag);
     }
     return $arrXML;
 }