function closeOrderImport($order_id, $leadtime_start_date, $item_total, $total_price)
 {
     if ($order_id !== false) {
         $class_jcust = Order::getOldOrderFunctionSPCustomers();
         $class_jcust->getFromOrder($order_id);
         $class_jo = Order::getOldOrderFunctionSP();
         $class_jo->leadtimeSetStart($leadtime_start_date, '', $order_id);
         if ($item_total > 1) {
             Order::updateOrderItemTotal($order_id, $item_total);
             Order::updateOrderTotalPrice($order_id, $total_price);
         }
     }
 }
             //if ring then change length from sku to cm
             if (Product::isUsingLengthInMilimeter($product->category_id)) {
                 //some ring products were uploaded with
                 //additional length added separated with "-"
                 if (!is_numeric($plength)) {
                     list($length_int, $length_ext) = explode('-', $plength);
                     $plength = $length_int;
                 }
                 $plength = $plength / 10;
             }
         }
         $article_id = $product->getArticleIDFromLength($plength);
     }
     $ean_no = $product->getEAN($article_id);
 }
 $o_detail = Order::getOldOrderFunctionSP()->retrieveDetail('', $order_number);
 if (count($o_detail) > 0) {
     echo "{$order_number}: {$seller_sku} -> {$ean_no}<br/>";
     $sp_type = 'S';
     $result_data = checkProductOnBag($sp_type, $o_detail['jng_sp_orders_id'], $ean_no);
     if ($result_data['status'] == 'MCCHECKPRODUCTONBAG') {
         $bin_type = 'bin_in';
         $order_product_id = $result_data['order_product_id'];
         $result_data = processReturn($bin_type, $sp_type, $order_product_id, 'manual', '0', $return_date);
         if ($result_data['status'] == 'CREATERETURNFAIL') {
             $failed[] = $order_number;
         } else {
             $success[] = $order_number;
         }
         echo "SP-{$order_product_id}: {$result_data['status']}<br/>";
     }
function importOttoB2BOrderFromArray($order, $xml_filename, $import_time)
{
    global $obj_sp, $logger;
    $orders_created = array();
    $jng_id = $order['OttoB2B:SupplierCode']['value'];
    if ($jng_id == $obj_sp->getExternalID()) {
        $order_buyer = $order['OttoB2B:BuyerAddress'];
        $order_billing = $order['OttoB2B:InvoiceAddress'];
        $order_delivery = $order['OttoB2B:DeliveryAddress'];
        //generate shipping name
        $full_shipping_name = $order_delivery['OttoB2B:Name']['value'];
        $name_limit = 32;
        //check if shipping name is too long
        if (strlen($full_shipping_name) <= $name_limit) {
            $shipping_firstname_text = $full_shipping_name;
            $shipping_lastname_text = '';
        } else {
            $logger->write('Shipping name is too long, run auto split');
            $shipping_name_split = explode(' ', $full_shipping_name);
            $shipping_firstname = array();
            $shipping_lastname = array();
            $firstname_full = false;
            $total_name_chars = 0;
            $name_word_counter = 0;
            foreach ($shipping_name_split as $name) {
                $name_word_counter++;
                $name_length = strlen($name);
                //consider space between word as part of $name_length
                if ($name_word_counter > 1) {
                    $name_length += 1;
                }
                //check if first name is already reach the limit
                if ($firstname_full || $total_name_chars + $name_length > $name_limit) {
                    //limit reached, use lastname
                    if (!$firstname_full) {
                        $firstname_full = true;
                    }
                    $shipping_lastname[] = $name;
                } else {
                    //all ok, use firstname
                    $total_name_chars += $name_length;
                    $shipping_firstname[] = $name;
                }
            }
            $shipping_firstname_text = implode(' ', $shipping_firstname);
            $shipping_lastname_text = implode(' ', $shipping_lastname);
            $logger->write('Firstname: ' . $shipping_firstname_text);
            $logger->write('Lastname: ' . $shipping_lastname_text);
        }
        $order_date = translateToMySqlDate($order['OttoB2B:OrderDate']['value']);
        $order_no = $order['OttoB2B:OrderNumber']['value'];
        $customer_billing_id = $order_billing['OttoB2B:Gln']['value'];
        $customer_billing_title = '';
        $customer_billing_firstname = $order_billing['OttoB2B:Name']['value'];
        $customer_billing_lastname = '';
        $customer_billing_address = $order_billing['OttoB2B:Street']['value'];
        $customer_billing_address2 = '';
        $customer_billing_city = $order_billing['OttoB2B:City']['value'];
        $customer_billing_postcode = $order_billing['OttoB2B:Zip']['value'];
        $customer_billing_country = $order_billing['OttoB2B:Country']['value'];
        $customer_billing_phone = $order_buyer['OttoB2B:ContactPhone']['value'];
        $customer_billing_phone2 = '';
        //we decided no need to grab the email address
        //$customer_billing_email = $order_buyer['OttoB2B:ContactEmail']['value'];
        $customer_billing_email = '';
        $customer_shipping_id = $order_delivery['OttoB2B:Gln']['value'];
        $customer_shipping_title = '';
        $customer_shipping_firstname = $shipping_firstname_text;
        $customer_shipping_lastname = $shipping_lastname_text;
        $customer_shipping_address = $order_delivery['OttoB2B:Street']['value'];
        $customer_shipping_address2 = '';
        $customer_shipping_city = $order_delivery['OttoB2B:City']['value'];
        $customer_shipping_postcode = $order_delivery['OttoB2B:Zip']['value'];
        $customer_shipping_country = $order_delivery['OttoB2B:Country']['value'];
        $customer_shipping_phone = '';
        $customer_shipping_phone2 = '';
        $customer_shipping_email = '';
        $expected_delivery_date = translateToMySqlDate($order['OttoB2B:DeliveryDate']['value']);
        $expected_delivery_date_from = 'null';
        $expected_delivery_date_until = 'null';
        $shipping_window_close = $expected_delivery_date;
        $shipping_window_open = date('Y-m-d', strtotime($shipping_window_close . ' -1 week'));
        $total_price = $order['OttoB2B:TotalPrice']['OttoB2B:Value']['value'];
        $shipping_cost = 0;
        if ($order['OttoB2B:TermsOfPayment']['value'] == Order::PAYMENT_METHOD_OTTO_B2B_1) {
            $payment_method = 'ottob2b1';
        } else {
            die('NEW UNKNOWN PAYMENT METHOD! Please report to IT Team');
        }
        $payment_status = 0;
        $item_counter = 0;
        $products_not_found = array();
        $prev_ean = '';
        foreach ($order['OttoB2B:OrderItems']['OttoB2B:Item'] as $item) {
            $item_counter++;
            $item_sizes = array();
            //There are ItemSize with 1 size and multiple sizes
            //Since the array returned by the function xmlToArray is different
            //We have to rebuild them in a new array again below
            if (isset($item['OttoB2B:ItemSizes']['OttoB2B:ItemSize']['OttoB2B:EAN'])) {
                $item_size = $item['OttoB2B:ItemSizes']['OttoB2B:ItemSize'];
                $item_sizes[] = $item_size;
            } else {
                foreach ($item['OttoB2B:ItemSizes']['OttoB2B:ItemSize'] as $item_size) {
                    $item_sizes[] = $item_size;
                }
            }
            //Loop through the multiple sizes
            foreach ($item_sizes as $item_size) {
                $ean = $item_size['OttoB2B:EAN']['value'];
                if ($ean != $prev_ean) {
                    $prev_ean = $ean;
                    $obj_product = Product::loadObjectFromEAN($ean);
                    if (is_null($obj_product->id)) {
                        $products_not_found[] = $ean;
                        $logger->write('PRODUCT NOT FOUND: ' . $ean);
                        continue;
                    }
                    $product_id = $obj_product->id;
                    $article_id = $obj_product->getArticleIDFromEAN($ean);
                }
                $external_item_id = $item['OttoB2B:ItemNumber']['value'];
                $billing_product_code = $item['OttoB2B:SupplierItemDescription']['value'];
                $billing_text = $item['OttoB2B:StyleNumber']['value'];
                $ordered_quantity = $item_size['OttoB2B:Quantity']['OttoB2B:Value']['value'];
                $price = $item_size['OttoB2B:Price']['OttoB2B:Value']['value'];
                $price_after_provision = $price;
                $item_count = 1;
                $item_total = 1;
                $external_item_count = $item_counter;
                $items_created = array();
                for ($qty = 1; $qty <= $ordered_quantity; $qty++) {
                    $shipment_id = $order_no . substr($ean, -6) . str_pad($qty, 4, '0', STR_PAD_LEFT);
                    $order_id = Order::createNewSalesPartnerOrder($obj_sp->id, basename($xml_filename), $jng_id, $order_date, $import_time, $shipment_id, $order_no, $customer_billing_id, $customer_billing_title, $customer_billing_firstname, $customer_billing_lastname, $customer_billing_address, $customer_billing_address2, $customer_billing_city, $customer_billing_postcode, $customer_billing_country, $customer_billing_phone, $customer_billing_phone2, $customer_billing_email, $customer_shipping_id, $customer_shipping_title, $customer_shipping_firstname, $customer_shipping_lastname, $customer_shipping_address, $customer_shipping_address2, $customer_shipping_city, $customer_shipping_postcode, $customer_shipping_country, $customer_shipping_phone, $customer_shipping_phone2, $customer_shipping_email, $expected_delivery_date, $expected_delivery_date_from, $expected_delivery_date_until, $total_price, $shipping_cost, $payment_method, $payment_status);
                    if ($order_id !== false) {
                        $item_id = Order::createNewSalesPartnerOrderItem($order_id, $product_id, $article_id, $ean, $external_item_id, $billing_product_code, $billing_text, 1, $price, $price_after_provision, $item_count, $item_total, $external_item_count, $shipping_window_open, $shipping_window_close);
                        $orders_created[] = $order_id;
                        $items_created[] = $item_id;
                        Order::getOldOrderFunctionSP()->leadtimeSetStart($import_time, null, $order_id);
                        $logger->write("Order {$order_no} EAN {$ean} Qty {$qty} created:" . " SP-{$item_id}");
                    } else {
                        $logger->write("Order {$order_no} EAN {$ean} Qty {$qty} Exist!");
                    }
                }
            }
        }
        if ($order_id !== false) {
            Order::getOldOrderFunctionSPCustomers()->getFromOrder($order_id);
        }
        if (count($orders_created) > 0) {
            Order::getOldOrderFunctionSP()->confirmOrders($orders_created, $import_time);
        }
        $products_not_found_total = count($products_not_found);
        if ($products_not_found_total > 0) {
            echo "{$products_not_found_total} EAN not found:<br />";
            foreach ($products_not_found as $ean) {
                echo "{$ean}<br />";
            }
        }
    } else {
        $logger->write('Order is not for J&G ID, import is aborted!');
    }
    return count($orders_created);
}
 private function queryOrdersItemsDetailSP($orders_items_id)
 {
     $return_status = in_array($this->filters_status, array('16', '17', '18'));
     $query = "SELECT CONCAT(jo.customer_billing_firstname,' ',jo.customer_billing_lastname) AS customer_name" . ", jo.cod_costs, jo.order_id, jo.order_date, jo.service_code, jo.customers_order_count" . ", jo.payment_method, jo.payment_status, joi.*, do.depot_orders_id" . ", do.status AS depot_orders_status, do.prod_status AS depot_orders_prod_status" . ", MAX(joih.status_date) AS status_date, MAX(psh.status_date) AS status_date_prod" . ", jcust.jng_sp_customers_id, jscs.list_type, sp.jng_sp_id, sp.package_prefix" . ", p.products_image, p.products_brand_id, p.material_expenses AS current_mat_exp" . ", ptc.categories_id, pi.invoice_complete_status" . ", " . payone_invoice::calcBalance('', true) . " AS invoice_current_balance" . ", pi.invoice_amount_paid, pi.is_captured, MAX(ope.last_sent_date) AS last_sent_date" . ", MAX(ope.sent_count) AS sent_count, pl.sold_monthly_1" . ", IFNULL(joi.leadtime_start_date, jo.order_date) AS date_for_sorting";
     if ($return_status) {
         $query .= ", MIN(joir.return_time) AS return_time, SUM(joir.return_quantity) AS return_quantity";
     }
     $query .= " FROM jng_sp_orders jo";
     $query .= " LEFT JOIN jng_sp sp ON sp.jng_sp_id = jo.jng_sp_id";
     $query .= " LEFT JOIN jng_sp_customers jcust " . " ON jcust.jng_sp_id = jo.jng_sp_id AND jcust.customer_id = jo.customer_billing_id";
     $query .= " LEFT JOIN jng_sp_customers_special jscs " . " ON jscs.jng_sp_customers_id = jcust.jng_sp_customers_id";
     $query .= " LEFT JOIN jng_sp_orders_items joi ON joi.jng_sp_orders_id = jo.jng_sp_orders_id";
     $query .= " LEFT JOIN depot_orders do " . " ON do.trans_type = 'SP' AND do.trans_id = joi.jng_sp_orders_items_id";
     $query .= " LEFT JOIN jng_sp_orders_items_status_history joih " . " ON joih.jng_sp_orders_items_id = joi.jng_sp_orders_items_id AND joih.status = joi.status";
     $query .= " LEFT JOIN production_status_history psh " . " ON psh.type = 'SP' AND psh.orders_items_id = joi.jng_sp_orders_items_id " . " AND psh.status = joi.prod_status";
     $query .= " LEFT JOIN products_log pl ON pl.products_id = joi.products_id";
     $query .= " LEFT JOIN products p ON p.products_id = joi.products_id";
     $query .= " LEFT JOIN products_to_categories ptc ON ptc.products_id = joi.products_id";
     $query .= " LEFT JOIN orders_products_email ope " . " ON ope.orders_products_id = joi.jng_sp_orders_items_id AND ope.type = 'S'";
     //retrieve MAX(ope.sent_count)
     $query .= " LEFT JOIN payone_invoice pi " . " ON pi.invoice_order_type = 'S' AND pi.invoice_order_id = jo.jng_sp_orders_id";
     if ($return_status) {
         $query .= " LEFT JOIN jng_sp_orders_items_return joir " . " ON joir.jng_sp_orders_items_id = joi.jng_sp_orders_items_id";
     }
     $query .= " WHERE joi.status = '{$this->filters_status}' AND joi.jng_sp_orders_items_id = '{$orders_items_id}'";
     if ($this->filters_order_type > 0) {
         $query .= " AND jo.jng_sp_id = {$this->filters_order_type} ";
     }
     $query .= $this->eanListFilterQuery('joi', $this->filters_list_ean, 'AND', '');
     $query .= $this->leadtimeFilterQuery($this->filters_status, 'joi.leadtime_start_date', 'jo.order_date', $this->filters_leadtime_date_start, $this->filters_leadtime_date_end, 'AND', '');
     $query .= $this->ordersNoFilterQuery('jo.order_id', $this->filters_list_orders_no, 'AND', '');
     if ($this->filters_brand_id > 0) {
         $query .= " AND p.products_brand_id = '{$this->filters_brand_id}' ";
     }
     if ($this->filters_cat_id > 0) {
         $query .= " AND ptc.categories_id = '{$this->filters_cat_id}' ";
     }
     if ($this->filters_sub_status != '') {
         if ($this->filters_status == '1') {
             //This will handle for tab Unpaid Prepayment, so far nothing todo
         } else {
             $query .= " AND joi.prod_status LIKE '{$this->filters_sub_status}%'";
         }
     }
     $query .= " AND " . Order::getOldOrderFunctionSP()->filterQueryForShippingWindow();
     $query .= " GROUP BY joi.jng_sp_orders_items_id";
     return $query;
 }
            }
            if (is_null($bin)) {
                $result['status'] = 'FULL';
            } else {
                $additional_info = count($dp_closed) == 0 ? '' : implode(',', $dp_closed) . ' ';
                $class_bin->bookBinForProduct($bin['bins_id'], $stock['products_stock_id']);
                Product::getOldProductFunction()->stockAdd($jng_warehouses_id, $products_id, $articles_id, $quantity, $additional_info . "Bin-In by {$username}");
                $pt->addDataToField(date('Y-m-d H:i:s'), 'log_products_bin_in', $quantity);
                //add to daily statistic
                if (count($items) > 0) {
                    foreach ($items as $item_id => $i) {
                        $class_do->updateStatus($item_id, '8', $username);
                        //if MMO, prioritize order for to use stock
                        if ($i_rack_flag == 'M') {
                            if ($i['trans_type'] == Order::ORDER_TYPE_SALES_PARTNER) {
                                Order::getOldOrderFunctionSP()->updateItemDSpriority($i['trans_id'], '1');
                            } elseif ($i['trans_type'] == Order::ORDER_TYPE_JULIE_GRACE) {
                                Order::getOldOrderFunctionJG()->updateProductDSpriority($i['trans_id'], '1');
                            }
                        }
                    }
                }
                $result['status'] = 'FOUND';
                $result['result_ean'] = $ean;
                $result['bin'] = $bin['code_clean'];
                $result['added'] = $quantity;
            }
        }
    }
}
//ajaxReturn($result);
Esempio n. 6
0
 public function cancel($updater)
 {
     $o = $this->getOrder();
     if ($o->isOrderFromSalesPartner()) {
         Order::getOldOrderFunctionSP()->doCancelOrders($this->item_id, $this->status, $updater);
     } elseif ($o->isOrderFromJulieGrace()) {
         Order::getOldOrderFunctionJG()->doCancelOrders($this->item_id, $this->status, $updater);
     }
 }