$q = "SELECT joi.jng_sp_orders_id, joi.jng_sp_orders_items_id, joi.status FROM jng_sp_orders jo";
    $q .= " INNER JOIN jng_sp_orders_items joi ON joi.jng_sp_orders_id=jo.jng_sp_orders_id AND joi.status={$REQUIRED_STATUS_AMVD_PICKNPACK} AND print_count=1";
    $q .= " WHERE jo.jng_sp_id IN ({$jng_sp_id}) AND jo.order_id='{$orders_id}'";
    $r = tep_db_query($q);
    $oids = array();
    $oiids = array();
    if (tep_db_num_rows($r) > 0) {
        while ($item = tep_db_fetch_array($r)) {
            $class_jo->updateItemStatus($item['jng_sp_orders_items_id'], $UPDATED_STATUS, $username);
            $orders_sent = true;
            if (!in_array($item['jng_sp_orders_id'], $oids)) {
                $oids[] = $item['jng_sp_orders_id'];
            }
            $oiids[] = $item['jng_sp_orders_items_id'];
        }
        $class_jo->printCountAdd($oiids);
    } else {
        $already_sent = true;
    }
    if ($orders_sent && !$already_sent) {
        $class_jo->setShipmentDateNonEasylog($oids);
    }
} else {
    use_class('jng_sp_orders');
    $class_jo = new jng_sp_orders();
    $items = $class_jo->retrieveItems($orders_id);
    foreach ($items as $item) {
        if (in_array($item['status'], $REQUIRED_STATUS)) {
            $class_jo->updateItemStatus($item['jng_sp_orders_items_id'], $UPDATED_STATUS, $username);
            $orders_sent = true;
        } elseif ($item['status'] == $UPDATED_STATUS) {
            */
            //Display 1 line All Quantity
            $pdf->total_ean_lines++;
            $pdf->setX($cellstart);
            $pdf->Cell($cell1size, $cell_height, $oi['products_ean']);
            $pdf->Cell($cell2size, $cell_height, $qty);
            $pdf->Cell($cell3size, $cell_height, $tbins_location, 0, 1);
        }
        $products_height = ($pdf->total_ean_lines + 1) * $cell_height;
        $pdf->ean_ypos += $products_height > 20 ? $products_height + 10 : 30;
        $firstorder = false;
    }
    global $class_jo, $class_o;
}
if ($atds) {
    use_class('production_target');
    $pt = new production_target();
    $timestamp = date('Y-m-d H:i:s');
    if ($total_products_picked > 0) {
        $pt->addDataToField($timestamp, 'log_products_picked_from_bin', $total_products_picked);
    }
    if (count($oi_printed_sp) > 0) {
        $class_jo->printCountAdd($oi_printed_sp);
    }
    if (count($oi_printed_jg) > 0) {
        $class_o->printCountAdd($oi_printed_jg);
    }
}
$filename = 'HH-Picklist-' . date('YmdHi');
$pdf->Output($filename . '.pdf', 'D');
tep_db_close();
 function printProductionInstruction()
 {
     global $ENGRAVED_PRODUCTS;
     //HEADER
     $header = array();
     $header[] = '<html>';
     $header[] = '<head>';
     $header[] = '<title>JULIE &amp; GRACE Production Instruction</title>';
     $header[] = '<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />';
     $header[] = '<link rel="stylesheet" type="text/css" href="production.css">';
     $header[] = '</head>';
     $header[] = '<body>';
     $header[] = '<div id="production">';
     //CONTENT:
     $pi_printed_jng = array();
     $pi_printed_sp = array();
     $pi_printed_dp = array();
     $content = array();
     foreach ($this->orders_products as $orders_id => $products) {
         foreach ($products as $p) {
             $order = $this->orders[$orders_id];
             ${'pi_printed_' . strtolower($order['type'])}[] = $p['item_id'];
             //CHECK CHANGE LENGTH
             $change_length_notice = '';
             if ($p['change_length'] != 0) {
                 $change_length_text = 'Change Length: <strong>' . $p['change_length'] . '</strong> / New Length: <strong>' . $p['final_length'] . 'cm</strong>';
                 $change_length_notice .= '<div class="table highlight-red red" style="font-size:14px;">' . $change_length_text . '</div>';
                 $change_length_notice .= '<div>&nbsp;</div>';
             }
             $content[] = '<div class="page">';
             if ($p['print_count'] > 0) {
                 $content[] = '<h3 style="margin-bottom:10px;">Print Copy #' . ($p['print_count'] + 1) . '</h3>';
             }
             $content[] = $this->printPageAdmin($p, $orders_id);
             if ($p['stock_status'] == 'P') {
                 $mat_list = $this->printMaterialList($p['id'], $p['detail_length'], $p['elements']['materials'], $p['qty'], $p['change_length']);
                 $ins_list = $this->printFGpickingList($p, $orders_id);
                 $rowcount_mat_list = 0;
                 $rowcount_ins_list = 5;
             } else {
                 $mat_list = $this->printMaterialList($p['id'], $p['detail_length'], $p['elements']['materials'], $p['qty'], $p['change_length']);
                 $rowcount_mat_list = count($p['elements']['materials']);
                 /*
                 if($p['type']=='CP') {
                     $ins_list = $this->printInstructionList($p['elements']['instruction']);
                     $rowcount_ins_list = $this->temp_rowcount_instruction_list;
                 } elseif($p['type']=='SP' || $p['type']=='NEP') {
                     $ins_list = $this->printManualInstructionList($p, $orders_id);
                     //['type'], $p['image'], $p['id'], $p['final_length'], $p['man_instruction'], $p['code']);
                     $rowcount_ins_list = 5;
                 } else {
                     $ins_list = '';
                     $rowcount_ins_list = 0;
                 }
                 */
                 $ins_list = $this->printManualInstructionList($p, $orders_id);
             }
             $content[] = $mat_list;
             $content[] = '</div>';
             $pagecount_ins_list = $this->temp_instruction_pages;
             $qcontrol = $p['type'] == 'NEP' ? '' : $this->printQualityControl($p);
             $list = array();
             $list[] = '<div class="page">';
             if ($mat_list != '' || $ins_list != '') {
                 //$list[] = '<div class="page-head">Production</div>';
                 $list[] = $change_length_notice;
                 if (is_array($ins_list)) {
                     $list[] = implode("\n", $ins_list);
                     $list[] = '<div style="clear:both;">&nbsp;</div>';
                 }
             }
             $list[] = $qcontrol;
             $list[] = '</div>';
             if (in_array($p['id'], $ENGRAVED_PRODUCTS) && isset($this->orders[$orders_id])) {
                 $list[] = $this->printEngravingInstruction($orders_id, $p);
             }
             $content[] = implode("\n", $list);
         }
     }
     //PI Print Counter
     if (count($pi_printed_sp) > 0) {
         use_class('jng_sp_orders');
         $class_jo = new jng_sp_orders();
         $class_jo->printCountAdd($pi_printed_sp);
     }
     if (count($pi_printed_jng) > 0) {
         //if(count($pi_printed_jg)>0) {   /*DEWA replaced 19112010 since 'type' above using JNG*/
         use_class('orders');
         $class_o = new orders();
         $class_o->printCountAdd($pi_printed_jng);
         //$class_o->printCountAdd($pi_printed_jg);
     }
     if (count($pi_printed_dp) > 0) {
         use_class('depot_orders');
         $class_do = new depot_orders();
         $class_do->printCountAdd($pi_printed_dp);
     }
     //PRINT SCRIPT
     $script = array();
     if ($this->printStatus) {
         $script[] = '<script type="text/javascript"><!--';
         $script[] = 'window.print();';
         $script[] = 'window.close();';
         $script[] = '--></script>';
     }
     //FOOTER
     $footer = array();
     $footer[] = '</div>';
     $footer[] = '</body>';
     $footer[] = '</html>';
     $pi = array();
     $pi[] = implode("\n", $header);
     foreach ($content as $c) {
         $pi[] = $c;
     }
     $pi[] = implode("\n", $script);
     $pi[] = implode("\n", $footer);
     $result = implode("\n", $pi);
     return $result;
 }