$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);
         $file_not_exist[] = $xml_filename;
     }
     $orders_created_total = count($orders_created);
     if ($orders_created_total > 0) {
         //SP handle by Tradebyte needs no confirmation,
         //so mark orders as confirmed directly
         $class_jo->confirmOrders($orders_created, $import_date);
         logThis("  = Auto confirm new orders");
         //Grab customers data from new orders and sync to existing SP customers data
         foreach ($orders_created as $orders_id) {
             $class_jcust->getFromOrder($orders_id);
         }
     }
 }
 $orders_prepayment_paid_total = count($orders_prepayment_paid);
 $orders_canceled_total = count($orders_canceled);
 if (!$zade_prepayment_need_refreshed) {
     $zade_prepayment_need_refreshed = $orders_prepayment_paid_total > 0 || $orders_canceled_total > 0;
 }
 //REFRESH STOCK BOOKING FOR ZALANDO PREPAYMENT ORDERS
 if ($zade_prepayment_need_refreshed) {
     zadeRefreshPrepaymentBooking();
         $xml_content .= writeXMLclose('product-line-item', 4);
     }
     $xml_content .= writeXMLclose('product-line-items', 3);
     $xml_content .= writeXMLclose('OrderState', 2);
     $xml_content .= writeXMLclose('OrderStates', 1);
     $xml_content .= writeXMLclose('ottopartner', 0);
     //CREATE XML ON SERVER
     $fn_counter = str_pad($ts_counter, 2, '0', STR_PAD_LEFT);
     $xml_filename = $temp_sp['jng_id'] . '_orderstatus_' . $ts_period . $fn_counter . '.xml';
     $xmlfullpath = SP_OTTODE_UPLOAD_PATH_STATES . $xml_filename;
     $file = fopen($xmlfullpath, 'w');
     $success = fwrite($file, $xml_content) !== false;
     fclose($file);
     if ($success) {
         $orders_confirmed++;
         $class_jo->confirmOrders($o['jng_sp_orders_id'], $timestamp);
         $archive_path_raw = createBackupDirectory(SP_OTTODE_ARCHIVE_PATH . 'confirm/');
         $archive_fullpath = $archive_path_raw . $xml_filename;
         while (file_exists($archive_fullpath)) {
             $archive_fullpath .= '_copy';
         }
         copy($xmlfullpath, $archive_fullpath);
         $need_jms_upload = true;
     }
     $logger->write("SP-{$o['jng_sp_orders_id']} is confirmed");
 }
 if ($need_jms_upload) {
     $upload_ok = executeOTTOShellscript(SP_OTTODE_SHELLSCRIPT_UPLOAD_ORDERSTATUS);
 }
 if ($orders_confirmed > 0) {
     if ($upload_ok) {
             //    Amazon Vendor    //
             /////////////////////////
         } else {
             $import_status = false;
         }
         if ($import_status) {
             $class_jd->updateDownloadImported($file['jng_sp_download_id']);
             $files_imported++;
             unlink($xmlfilename);
         }
     }
 }
 if (count($orders_created_collection) > 0) {
     //NM.AT needs no confirmation, so update confirmation data directly
     if ($jng_sp_id == '3') {
         $class_jo->confirmOrders($orders_created_collection, $import_date);
     }
     //Grab customers data from new orders and sync to existing SP customers data
     foreach ($orders_created_collection as $order_id) {
         $class_jcust->getFromOrder($order_id);
     }
 }
 $content .= '<div style="margin-bottom:30px;">';
 $h2 = '<h2>' . $jng_sp_name . '</h2>';
 if ($orders_created > 0) {
     $content .= $h2;
     $tobe = $files_imported == 1 ? ' is' : 's are';
     $content .= "<h3>{$files_imported} File{$tobe} successfully imported</h3>";
     $content .= "<h3>{$orders_created} Orders contain {$products_created} Products are generated</h3>";
 } else {
     $content .= $h2;
     $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
     if ($conn_id && $login_result) {
         $contents = ftp_nlist($conn_id, $ftp_file_path);
         if (is_array($contents) && count($contents) > 0) {
             if (in_array($xml_filename_encrypted, $contents)) {
                 ftp_delete($conn_id, $xml_filename_encrypted);
             }
         }
         $success_upload = ftp_put($conn_id, $ftp_file_path . $xml_filename_encrypted, $encrypted_file, FTP_BINARY);
         if ($success_upload) {
             $upload_id = $class_ju->newUpload($jng_sp_id, 'ORDRSP', $xml_filename_encrypted, $session_userinfo['username']);
             $uploaded_size = ftp_size($conn_id, $ftp_file_path . $xml_filename_encrypted);
             $local_size = filesize($encrypted_file);
             if ($uploaded_size == $local_size) {
                 $class_ju->updateStatus($upload_id, 'S', 'auto-check');
                 $class_jo->confirmOrders($orders_confirmed, $export_date);
                 $content .= '<h3 class="green">' . $jng_sp_name . ': ORDRSP XML File is uploaded successfully</h3>';
             } else {
                 $content .= '<h3 class="red">' . $jng_sp_name . ': ORDRSP XML File is not uploaded successfully, please try again.</h3>';
             }
         } else {
             $content .= '<h3 class="red">' . $jng_sp_name . ': Upload file failed</h3>';
         }
         ftp_close($conn_id);
     } else {
         $content .= '<h3 class="red">' . $jng_sp_name . ': Failed connecting to FTP server, please try again later.</h3>';
     }
 } else {
     $content .= '<h3 class="red">' . $jng_sp_name . ': Failed encrypting file, please contact administrator</h3>';
 }
 if (file_exists($encrypted_file)) {