if ($hour_now != $HOUREND || $hour_now == $HOUREND && $total_pids_left <= $max_pid_processed_per_run) {
     if ($total_pids_left == 0) {
         doUpload();
         exit;
     }
     //Necklace
     $component_length_id['2'] = '12118771';
     $component_length_name['2'] = 'Kettenlänge ca. (in cm)';
     //Bracelet
     $component_length_id['3'] = '12118781';
     $component_length_name['3'] = 'Armbandlänge ca. (in cm)';
     //Ring
     $component_length_id['29'] = '967701';
     $component_length_name['29'] = 'Durchmesser (ca. mm)';
     $sp_prefix = substr($sp_detail['jng_id'], -3);
     $nbt = neckermannDateFormat(date('Y-m-d H:i:s', strtotime("+1 day")));
     //XML STARTER
     if ($first_run) {
         $xml_content = '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n";
         //$xml_content .= '<NVAG_CATALOG xmlns="http://www.neckermann.de/Grossist/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neckermann.de/Grossist/XMLSchema http://www.neckermann.de/Grossist/XMLSchema/nvagcat_0_9_4_6.xsd">';
         $xml_content .= '<NVAG_CATALOG xmlns="http://www.neckermann.de/Grossist/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neckermann.de/Grossist/XMLSchema  http://www.neckermann.de/Grossist/XMLSchema/nvagcat_0_9_4_7.xsd">';
         $xml_content .= writeLine();
         //XML BASIC INFO
         $xml_content .= writeXMLline('SUP_ID', $sp_detail['jng_id'], 0);
         $xml_content .= writeXMLline('NEXT_ACCOUNTING_TIME', $nbt, 0);
         $xml_content .= writeXMLopen('SUPPLIER', 0);
         $xml_content .= writeXMLline('NAME', $jng_name, 1);
         $xml_content .= writeXMLline('CONTACT', $jng_contact, 1);
         $xml_content .= writeXMLline('STREET', $jng_street, 1);
         $xml_content .= writeXMLline('ZIP', $jng_zip, 1);
         $xml_content .= writeXMLline('CITY', $jng_city, 1);
 //$xml_content .= '<NECKERMANN_BDATA totalcount="'.$total_orders.'" xmlns="http://www.neckermann.de/Grossist/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neckermann.de/Grossist/XMLSchema http://www.neckermann.de/Grossist/XMLSchema/neckbdat_1_0_0.xsd">';
 $xml_content .= '<NECKERMANN_BDATA totalcount="' . $total_orders . '" xmlns="http://www.neckermann.de/Grossist/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neckermann.de/Grossist/XMLSchema http://www.neckermann.de/Grossist/XMLSchema/neckbdat_3_0_1.xsd">';
 $xml_content .= writeLine();
 //XML PER ORDER
 $orders_confirmed = array();
 foreach ($orders as $counter => $o) {
     $orders_confirmed[] = $o['jng_sp_orders_id'];
     //BDATA
     $xml_content .= writeXMLopen('BDATA', 1, 'counter="' . ($counter + 1) . '"');
     //HEADER
     $xml_content .= writeXMLopen('HEADER', 2);
     //Tech Data
     $xml_content .= writeXMLopen('TECH_DATA', 3);
     $xml_content .= writeXMLline('KQ_CLIENT_ID', '001', 4);
     $xml_content .= writeXMLline('MSG_TYPE', 'ORDRSP_AUF', 4);
     $xml_content .= writeXMLline('CREATION_TIME', neckermannDateFormat(), 4);
     $xml_content .= writeXMLline('ILN_SUPPLIER', $o['iln_jng'], 4);
     $xml_content .= writeXMLline('ILN_AGENT', $o['iln_sp'], 4);
     $xml_content .= writeXMLline('SUP_ID', $o['sp_jng_id'], 4);
     $xml_content .= writeXMLclose('TECH_DATA', 3);
     //Order Data
     $xml_content .= writeXMLopen('ORDER_DATA', 3);
     $xml_content .= writeXMLopen('NECKERMANN_ORDER_REFERENCE', 4);
     $xml_content .= writeXMLline('SHIPMENT_ID', $o['shipment_id'], 5);
     $xml_content .= writeXMLline('ORDER_ID', $o['order_id'], 5);
     $xml_content .= writeXMLline('BILL_ID', $o['bill_id'], 5);
     $xml_content .= writeXMLclose('NECKERMANN_ORDER_REFERENCE', 4);
     $xml_content .= writeXMLclose('ORDER_DATA', 3);
     //Customer Data
     $xml_content .= writeXMLopen('ORDER_SELLTO', 3);
     $xml_content .= writeXMLline('NECKERMANN_CUSTOMER_ID', $o['customer_billing_id'], 4);
         $delivery_replacement_time = '';
     } else {
         $replacement = 'J';
         $delivery_replacement_time = $delivery_time + 2;
     }
     $result .= writeXMLopen('A_DELIVERY', 2);
     $result .= writeXMLline('DELIVERY_TIME', $delivery_time, 3);
     $result .= writeXMLline('DELIVERY_REPLACEMENT', $replacement, 3);
     $result .= writeXMLline('DELIVERY_REPLACEMENT_TIME', $delivery_replacement_time, 3);
     $result .= writeXMLclose('A_DELIVERY', 2);
     $result .= writeLine();
     $result .= writeXMLclose('ARTICLEDATA', 1);
     $result .= writeLine();
     return $result;
 }
 $nbt = neckermannDateFormat(date('Y-m-d H:i:s', strtotime("+4 hours")));
 $bgst = $class_pm->retrieveBestGoodSettings();
 $hide_extreme_flag = $bgst['hidenostock_xtreme'] == '1';
 $hide_hard_flag = $bgst['hidenostock_hard'] == '1';
 $hide_nostock_flag = $bgst['hidenostock_somesp'] == '1';
 $products_stock = $class_pm->stockRetrieveAll(WAREHOUSE_ID_PRODUCTS_HAMBURG);
 $products = $class_jc->retrieveCatalogForUpload($jng_sp_id, true);
 if (count($products) == 0) {
     $cron_result[] = 'No Products found';
 } else {
     $xml_filename = $sp_detail['jng_id'] . 'pri.xml';
     $xml_filename_marker = $sp_detail['jng_id'] . 'pri.done';
     //XML STARTER
     $xml_content = '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n";
     //$xml_content .= '<NVAG_CATALOG xmlns="http://www.neckermann.de/Grossist/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neckermann.de/Grossist/XMLSchema http://www.neckermann.de/Grossist/XMLSchema/nvagpri_0_5_3.xsd">';
     $xml_content .= '<NVAG_CATALOG xmlns="http://www.neckermann.de/Grossist/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neckermann.de/Grossist/XMLSchema http://www.neckermann.de/Grossist/XMLSchema/nvagpri_0_5_4.xsd">';