$success_upload = false;
 if ($tb->send($xml_filename, $target_filename)) {
     rename($xml_filename, TRADEBYTE_ARCHIVE_MESSAGES_PATH . $xml_file);
     $success_upload = true;
 }
 $tb->disconnect();
 if ($success_upload) {
     $logger->write("Success sent MESSAGES xml {$xml_file} to TB");
     $total_confirm_R = count($items_confirmed['R']);
     if ($total_confirm_R > 0) {
         $class_jo->confirmOrderReturn($items_confirmed['R']);
         $logger->write("{$total_confirm_R} returned items confirmed");
     }
     $total_confirm_S = count($items_confirmed['S']);
     if ($total_confirm_S > 0) {
         $class_jo->confirmOrderDelivery($items_confirmed['S']);
         $logger->write("{$total_confirm_S} sent/canceled items confirmed");
     }
 } else {
     $logger->write("Failed sent MESSAGES xml {$xml_file} to TB");
 }
 //DELIVERY NOTIFICATION IS HANDLED IN cron/dhl-easylog-export-processor.php
 if (count($orders_canceled) > 0) {
     //CONFIRM CANCELATION DIRECTLY TO CUSTOMER
     $email_sent = 0;
     $orders_canceled = array_unique($orders_canceled);
     foreach ($orders_canceled as $order_id) {
         $order = new Order(Order::ORDER_TYPE_SALES_PARTNER, $order_id);
         $is_prepayment = $order->payment_method == Order::PAYMENT_METHOD_PREPAYMENT;
         if (!$is_prepayment || $is_prepayment && $order->is_paid) {
             $sent = $order->sendCancelNotification();
                 tep_mail(EMAIL_NAME_DEBUGR, EMAIL_ADDRESS_DEBUGR, $subject, $send_message, FROM_EMAIL_NAME, FROM_EMAIL_ADDRESS, false);
             }
         }
         //CHECK IF ORDER IS ALREADY CANCELED IN TBONE
         $items_canceled = array();
         if ($tb_confirmed_void && $orders_id > 0 && count($items_ids) > 0) {
             foreach ($items_ids as $item_id) {
                 $class_jo->doCancelOrders($item_id, '1', 'auto-set');
                 $items_canceled[] = $item_id;
             }
             logThis("  = Auto cancel order");
             $orders_canceled[] = $orders_id;
         }
         //Set auto cancel items as confirmed
         if (count($items_canceled) > 0) {
             $class_jo->confirmOrderDelivery($items_canceled);
             logThis("  = Auto confirm canceled orders");
         }
     }
     $files_imported++;
     $done_filename = TRADEBYTE_ARCHIVE_ORDERS_PATH . $o_file['filename'];
     //SET AS FILES IMPORTED AND MOVE IT TO archive
     $class_jd->updateDownloadImported($o_file['jng_sp_download_id']);
     rename($xml_filename, $done_filename);
 } else {
     logThis('- Failed to locate file');
     $subject = 'IMPORTANT & URGENT:  Import Order from Tradebyte Failed';
     $send_message = 'Manobo FAILED TO LOCATE BELOW FILE: ';
     $send_message .= '<br />' . $xml_filename;
     $send_message .= '<br /><br />Please check root cause and make sure new orders are imported!';
     tep_mail(EMAIL_NAME_DEBUGR, EMAIL_ADDRESS_DEBUGR, $subject, $send_message, FROM_EMAIL_NAME, FROM_EMAIL_ADDRESS, false);
        header('Content-Disposition: attachment; filename="' . str_replace('.xls', '-Confirmed.xml', $file['name']) . '"');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . strlen($xmlResult));
        ob_clean();
        flush();
        echo $xmlResult;
        if (count($orders_confirmed) > 0) {
            $sda = array('idcode_ship' => $asn_number);
            $filter = "jng_sp_id=5 AND jng_sp_orders_id IN (" . implode(',', $orders_confirmed) . ")";
            tep_db_perform('jng_sp_orders', $sda, 'update', $filter);
        }
        if (count($items_confirmed) > 0) {
            $class_jo->confirmOrderDelivery($items_confirmed);
        }
        exit;
    } else {
        $messagebox->add('Update ASN Failed! Only XML and Excel File are allowed, please check your file: ' . $file['type']);
    }
}
if (isset($_FILES['amvdsscc'])) {
    $spid = tep_db_prepare_input($_POST['spid']);
    $destination = tep_db_prepare_input($_POST['destination']);
    $order_type = tep_db_prepare_input($_POST['order_type']);
    $date_send = generateMysqlDateFromGerman(tep_db_prepare_input($_POST['date_send']));
    $box_total = tep_db_prepare_input($_POST['box_total']);
    if ($_POST['box_switch_time'] == "") {
        $box_switch_time = null;
    } else {