/** * Get vip status of customer from an order * @param String $type * @param Int $orders_id * @return Boolean */ function checkCustomerIsVIP($type, $orders_id) { $type = strtoupper($type); $is_vip = false; if ($type == 'SP') { use_class('jng_sp_orders'); use_class('jng_sp_customers'); use_class('jng_sp_customers_special'); $class_jo = new jng_sp_orders(); $class_jc = new jng_sp_customers(); $class_jcs = new jng_sp_customers_special(); $o = $class_jo->retrieveDetail($orders_id); //GET CUSTOMER DETAIL VIP OR NOT $cust_data = $class_jc->retrieveDetail(null, $o['jng_sp_id'], $o['customer_billing_id']); if (is_array($cust_data) && $cust_data['jng_sp_customers_id'] > 0) { $cust_detail = $class_jcs->getCustomerDetail($cust_data['jng_sp_customers_id']); } $is_vip = $cust_detail['list_type'] == 'V'; } elseif ($type == 'JG') { use_class('orders'); use_class('customers_special_list'); $class_o = new orders(); $class_csl = new customers_special_list(); $o = $class_o->retrieveDetail($orders_id); //GET CUSTOMER DETAIL VIP OR NOT $cust_detail = $class_csl->getCustomerDetail($o['customers_id']); $is_vip = $cust_detail['list_type'] == 'V'; } elseif ($type == 'DP') { use_class('depot_orders'); $class_do = new depot_orders(); $do = $class_do->retrieveDetail($orders_id); if ($do['trans_type'] == 'SP' || $do['trans_type'] == 'JG') { if ($do['trans_type'] == 'SP') { use_class('jng_sp_orders'); $class_jo = new jng_sp_orders(); $it = $class_jo->retrieveItemDetail($do['trans_id']); $orders_id = $it['jng_sp_orders_id']; } elseif ($do['trans_type'] == 'JG') { use_class('orders'); $class_o = new orders(); $it = $class_o->retrieveProductDetail($do['trans_id']); $orders_id = $it['orders_id']; } $is_vip = checkCustomerIsVIP($do['trans_type'], $orders_id); } } return $is_vip; }
function getOrderDetail($barcode = '', $idcode_ret = '') { //die("$barcode | $idcode_ret"); $result = array(); $result['status'] = 'MCORDERNOTFOUND'; use_class('jng_sp'); use_class('jng_sp_orders'); if ($barcode != '') { list($type, $order_product_id) = split('-', strtoupper($barcode)); //GET order_id $order_id = ''; if ($type == 'SP' || $type == 'JR') { $status = 'MCSCANPRODUCT'; use_class('jng_sp_customers'); $class_sp = new jng_sp(); $class_jo = new jng_sp_orders(); $class_jc = new jng_sp_customers(); $item = $class_jo->retrieveItemDetail($order_product_id); $order_id = $item['jng_sp_orders_id']; $order = $class_jo->retrieveDetail($order_id); if (count($order) > 0) { $sp = $class_sp->retrieveDetail($order['jng_sp_id']); $customer = $class_jc->retrieveDetail(null, $order['jng_sp_id'], $order['customer_billing_id']); $customer_name = $order['customer_billing_firstname'] . ' ' . $order['customer_billing_lastname']; $customers_street_address = $order['customer_billing_address'] . ' ' . $order['customer_billing_address2']; $order_type = $sp['name'] . ' Order ' . $order['order_id']; $result = setOrderResult($status, 'S', $order_id, $order_type, $customer['jng_sp_customers_id'], $customer_name, $order['customer_billing_email'], $order['customer_billing_phone'], $customers_street_address, $order['customer_billing_postcode'], $order['customer_billing_city'], $order['customer_billing_country']); } } elseif ($type == 'JG') { $status = 'MCSCANPRODUCT'; use_class('orders'); $class_o = new orders(); $item = $class_o->retrieveProductDetail($order_product_id); $order_id = $item['orders_id']; $order = $class_o->retrieveDetail($order_id); if (count($order) > 0) { $order_type = 'J&G Order ' . $order['orders_no']; $result = setOrderResult($status, 'J', $order_id, $order_type, $order['customers_id'], $order['customers_name'], $order['customers_email_address'], $order['customers_telephone'], $order['customers_street_address'], $order['customers_postcode'], $order['customers_city'], $order['customers_country']); } } } elseif ($idcode_ret != '') { //1 idcode_ret utk 1 order $qsp = "SELECT j.name AS sp_name, jo.* FROM jng_sp_orders jo INNER JOIN jng_sp j ON j.jng_sp_id = jo.jng_sp_id"; $qsp .= " WHERE idcode_ret = '{$idcode_ret}' ORDER BY jo.order_date DESC LIMIT 1"; $rsp = tep_db_query($qsp); $dsp = tep_db_num_rows($rsp) > 0 ? tep_db_fetch_array($rsp) : null; if (is_null($dsp)) { /* 12.05.2015: * If not found, try to search using order number. * So far at this time, returns from LZ.ID, ZR.ID, ZR.BR used order number barcode */ $qsp = "SELECT j.name AS sp_name, jo.* FROM jng_sp_orders jo INNER JOIN jng_sp j ON j.jng_sp_id = jo.jng_sp_id"; $qsp .= " WHERE jo.order_id = '{$idcode_ret}' ORDER BY jo.order_date DESC LIMIT 1"; $rsp = tep_db_query($qsp); $dsp = tep_db_num_rows($rsp) > 0 ? tep_db_fetch_array($rsp) : null; } $qjg = "SELECT * FROM orders WHERE idcode_ret='{$idcode_ret}' ORDER BY date_purchased DESC LIMIT 1"; $rjg = tep_db_query($qjg); $djg = tep_db_num_rows($rjg) > 0 ? tep_db_fetch_array($rjg) : null; if (!is_null($dsp) || !is_null($djg)) { $status = 'MCSCANPRODUCT'; if (!is_null($dsp) && !is_null($djg)) { $dsp_time = strtotime($dsp['order_date']); $djg_time = strtotime($djg['date_purchased']); $use_data = $dsp_time >= $djg_time ? 'sp' : 'jg'; } else { $use_data = !is_null($dsp) ? 'sp' : 'jg'; } if ($use_data == 'sp') { $order_id = $dsp['jng_sp_orders_id']; use_class('jng_sp_customers'); $class_jc = new jng_sp_customers(); $customer = $class_jc->retrieveDetail(null, $dsp['jng_sp_id'], $dsp['customer_billing_id']); $customer_name = $dsp['customer_billing_firstname'] . ' ' . $dsp['customer_billing_lastname']; $customers_street_address = $dsp['customer_billing_address'] . ' ' . $dsp['customer_billing_address2']; $order_type = $dsp['sp_name'] . ' Order ' . $dsp['order_id']; $result = setOrderResult($status, 'S', $order_id, $order_type, $customer['jng_sp_customers_id'], $customer_name, $dsp['customer_billing_email'], $dsp['customer_billing_phone'], $customers_street_address, $dsp['customer_billing_postcode'], $dsp['customer_billing_city'], $dsp['customer_billing_country']); } else { $order_id = $djg['orders_id']; $order_type = 'J&G Order ' . $djg['orders_no']; $result = setOrderResult($status, 'J', $order_id, $order_type, $djg['customers_id'], $djg['customers_name'], $djg['customers_email_address'], $djg['customers_telephone'], $djg['customers_street_address'], $djg['customers_postcode'], $djg['customers_city'], $djg['customers_country']); } } } return $result; }
$class_jo = new jng_sp_orders(); $class_jcust = new jng_sp_customers(); $class_payone = new payone(); //SP SETTING salesPartnerCombo(); //AJAX ACTION if (isset($_POST['me_action'])) { if ($_POST['me_action'] == 'LOADUNSUBMITTEDORDERS') { $orders = $class_payone->newSPorders($jng_sp_id); $result = $class_payone->drawListTable($orders); } elseif ($_POST['me_action'] == 'AUTHORIZATION') { $process_method = 'authorization'; $order_id = tep_db_prepare_input($_POST['orders_id']); $order = $class_jo->retrieveDetail($order_id); $items = $class_jo->retrieveItems($order_id); $cust = $class_jcust->retrieveDetail(null, $order['jng_sp_id'], $order['customer_billing_id']); foreach ($items as $key => $i) { if ($class_jo->statusIsCancelled($i['status'])) { unset($items[$key]); } } $payi = new payone_invoice(); $payi->createFromOrderSP($order, $items); if (count($order) == 0 || count($items) == 0 || $payi->detail['invoice_complete_status'] != '0') { $result = "{$order_id},1"; } else { //--PREPARE PARAMETERS $request = array(); //--STANDARD PARAMETERS $request['mid'] = PAYONE_MERCHANT_ID; $request['portalid'] = PAYONE_PORTAL_ID;
function createReturnContainerSP($return_id, $return_qty, $joi_id) { use_class('Order'); use_class('jng_sp_orders'); use_class('jng_sp_customers'); use_class('payone_invoice'); $class_jcust = new jng_sp_customers(); $class_jo = new jng_sp_orders(); $item = $class_jo->retrieveItemDetail($joi_id); $oid = $item['jng_sp_orders_id']; $order_obj = new Order(Order::ORDER_TYPE_SALES_PARTNER, $oid); $order = $class_jo->retrieveDetail($oid); if ($order_obj->isPaymentHandledByPayone()) { $invoice = new payone_invoice('invoice_order_type', 'S', "invoice_order_id={$oid}"); //ONLY QUEING JUST FOR TRANSACTION THAT HAVE payone_txid (FIRST GET FROM SUBMITTING INVOICE) if ($invoice->detail['payone_txid'] != '') { $payone_txid = $invoice->detail['payone_txid']; $payment_method = $order_obj->getPaymentMethodRaw(); $customer = $class_jcust->retrieveDetail(null, $order_obj->sales_partner_id, $order_obj->customer_id); $customer_bankdata = $class_jcust->getBankAccountData($customer['jng_sp_customers_id']); $data_por = array(); $data_por['return_id'] = $return_id; $data_por['jng_sp_orders_items_id'] = $joi_id; $data_por['jng_sp_customers_id'] = $customer['jng_sp_customers_id']; $data_por['amount'] = round($return_qty * ($item['price'] * 100)); $data_por['txid'] = $payone_txid; $data_por['invoice_id'] = $invoice->detail['invoice_id']; $data_por['invoice_no'] = $invoice->detail['invoice_no']; $data_por['id'] = $item['article_number']; $data_por['pr'] = round($item['price'] * 100); $data_por['no'] = $return_qty; $data_por['de'] = strlen($item['billing_text']) > 32 ? substr($item['billing_text'], 0, 32) : $item['billing_text']; $data_por['va'] = 0; $data_por['payment_method'] = $payment_method; $data_por['currency'] = 'EUR'; if (!is_null($customer_bankdata)) { $data_por['bankcode'] = $customer_bankdata['bank_code']; $data_por['bankcountry'] = $customer_bankdata['bank_country']; $data_por['bankaccount'] = $customer_bankdata['bank_account_number']; $data_por['bankaccountholder'] = $customer_bankdata['bank_account_holder']; } $this->payoneReturnItemContainer($data_por); $items_total = $order_obj->getTotalItemsNotCanceledQuantity(); $returns_total = $order_obj->getTotalItemsReturnedQuantity(); if ($items_total == $returns_total) { $amount_paid = $invoice->detail['invoice_amount_paid']; $shipping_cost = $order_obj->getCostShipping(); $cod_cost = $order_obj->getCostCOD(); $total_costs = $shipping_cost + $cod_cost; if ($shipping_cost > 0) { //if((($amount_paid*1)==0)||(($amount_paid<>$shipping_cost)&&($amount_paid<>$total_costs))){ if ($amount_paid * 1 == 0 || $amount_paid > $total_costs) { //HANDLE DOUBLE OR MORE SHIPING RETURN CONTAINER $q_check = "SELECT * FROM payone_orders_return WHERE txid = '{$payone_txid}' AND id = 'Shipping'"; $dbc = tep_db_query($q_check); if (tep_db_num_rows($dbc) == 0) { $amount = round($shipping_cost * 100); $data_por = array(); $data_por['return_id'] = 0; $data_por['jng_sp_orders_items_id'] = 0; $data_por['jng_sp_customers_id'] = $customer['jng_sp_customers_id']; $data_por['amount'] = $amount; $data_por['txid'] = $payone_txid; $data_por['invoice_id'] = $invoice->detail['invoice_id']; $data_por['invoice_no'] = $invoice->detail['invoice_no']; $data_por['id'] = 'Shipping'; $data_por['pr'] = $amount; $data_por['no'] = 1; $data_por['de'] = 'Verpackung & Versand'; $data_por['va'] = 0; $data_por['payment_method'] = $payment_method; $data_por['currency'] = 'EUR'; $this->payoneReturnItemContainer($data_por); } } } if ($cod_cost > 0) { //if((($amount_paid==0*1))||(($amount_paid<>$cod_cost)&&($amount_paid<>$total_costs))){ if ($amount_paid * 1 == 0 || $amount_paid > $total_costs) { $amount = round($cod_cost * 100); $data_por = array(); $data_por['return_id'] = 0; $data_por['jng_sp_orders_items_id'] = 0; $data_por['jng_sp_customers_id'] = $customer['jng_sp_customers_id']; $data_por['amount'] = $amount; $data_por['txid'] = $payone_txid; $data_por['invoice_id'] = $invoice->detail['invoice_id']; $data_por['invoice_no'] = $invoice->detail['invoice_no']; $data_por['id'] = 'COD'; $data_por['pr'] = $amount; $data_por['no'] = 1; $data_por['de'] = 'Nachnahmegebühren'; $data_por['va'] = 0; $data_por['payment_method'] = $payment_method; $data_por['currency'] = 'EUR'; $this->payoneReturnItemContainer($data_por); } } } } else { //ORDER NOT SUBMITTED YET TO PAYONE, SO NO TXID CREATED YET. JUST NEED TO EXCLUDE ITEM FROM payone_invoice TABLE COLUMN 'invoice_order_items_id' $oids_arr = explode(',', $invoice->detail['invoice_order_items_id']); if (is_array($oids_arr)) { $new_amount = $invoice->detail['invoice_amount'] - $return_qty * $item['price']; foreach ($oids_arr as $key => $value) { if ($value == $joi_id) { unset($oids_arr[$key]); } } $oids = implode(',', $oids_arr); if (count($oids_arr) == 0) { //ALL PRODUCTS RETURNED $new_amount = 0; $invoice->updateCompleteStatus('3'); //INVOICE CANCELLED } tep_db_perform('payone_invoice', array('invoice_amount' => $new_amount, 'invoice_order_items_id' => $oids), 'update', "invoice_id = '" . $invoice->detail['invoice_id'] . "'"); } } } }
$comment_id = tep_db_prepare_input($_POST['comment_id']); $class_jcs->deleteComment($customer_id, $comment_id); echo utf8_encode($comment_id); exit; } elseif ($_POST['me_action'] == 'SAVETEXTALERT') { $text_alert = tep_db_prepare_input(utf8_decode($_POST['text_alert'])); $result = $class_jcs->updateCustomer($jng_sp_customers_id, 'text_alert', $text_alert); exit; } elseif ($_POST['me_action'] == 'CHANGELISTTYPE') { $new_type = tep_db_prepare_input(utf8_decode($_POST['new_type'])); $result = $class_jcs->updateCustomer($jng_sp_customers_id, 'list_type', $new_type); exit; } } //START TEMPLATE $customer = $class_jcust->retrieveDetail($jng_sp_customers_id); $sp_detail = $class_sp->retrieveDetail($customer['jng_sp_id']); $total_orders = $class_jcust->retrieveTotalOrders($jng_sp_customers_id); $total_products_ordered = $class_jcust->retrieveTotalProductsOrdered($jng_sp_customers_id); $typeimg = $class_jcs->getTypeSymbol($detail['list_type']); $typename = $class_jcs->getTypeName($detail['list_type']); $content = ''; $content .= '<div style="float:left;width:330px;">'; $content .= '<table border="0" cellpadding="0" cellspacing="0">'; $content .= '<tr><td colspan="2"><h2 style="margin:0;"><a href="?open=sp-customer&id=' . $jng_sp_customers_id . '" title="View Customer Detail">' . $customer['customer_firstname'] . ' ' . $customer['customer_lastname'] . '</a></h2></td></tr>'; //$content .= '<tr><td width="110">Partner</td><td>'.$sp_detail['name'].'</td></tr>'; //$content .= '<tr><td width="110">Email Address</td><td>'.$customer['customer_email'].'</td></tr>'; $content .= '<tr><td colspan="2"><div id="btn-mover">'; if ($detail['list_type'] == 'N') { $content .= '<input type="button" class="red" name="B" Value="Add to Blacklist" title="Add Customer to Blacklist" />'; $content .= '<input type="button" class="red" name="V" Value="Upgrade as VIP" title="Upgrade Customer as VIP" />';
$archive_fullpath = $archive_path_raw . $xml_filename; while (file_exists($archive_fullpath)) { $archive_fullpath .= '_copy'; } copy($xmlfullpath, $archive_fullpath); } //CONFIRM DIRECTLY TO CUSTOMER use_class('jng_sp_customers'); $class_jcust = new jng_sp_customers(); $counter_success = 0; $counter_fail = 0; $counter_noemail = 0; foreach ($orders as $counter => $o) { $to_name = "{$o['customer_billing_title']} {$o['customer_billing_firstname']} {$o['customer_billing_lastname']}"; $to_email_address = $o['customer_billing_email']; $customer = $class_jcust->retrieveDetail(null, $jng_sp_id, $o['customer_billing_id']); //we stop asking customers for bank account (31.01.2014) //$cid = $customer['jng_sp_customers_id']; //$time = time(); //$md5_cidtime = md5($cid+$time); //$key = $cid.$md5_cidtime.$cid; //$link = 'http://'.JNG_LIVE_URL.'/extensions/sp-customers-bank-account.php?'; //$link .= 'cid='.$cid.'&t='.$time.'&key='.$key; //$link_html = '<a href="'.$link.'">'.$link.'</a>'; if ($to_email_address == '') { $counter_noemail++; } else { $order_id = $o['order_id']; $order_date = date('d.m.Y', strtotime($o['order_date'])); $items = $data_sp['items'][$o['jng_sp_orders_id']]; $email_text_products = array();
$address_options[$ca['address_id']] = $ca['city'] . ', ' . $ca['address']; } $ajaxResult = array(); $ajaxResult['row_index'] = $_POST['row_index']; $ajaxResult['address_combo'] = '<select name="cust-address" class="input2"><option value="0">Please choose...</option>' . loadComboListFromArray($address_options) . '</select>'; ajaxReturn($ajaxResult); exit; } elseif ($_POST['me_action'] == 'CREATEORDERS') { if (is_array($_POST['customers']) && is_array($_POST['articles'])) { $timestamp = date('Y-m-d H:i:s'); $orders_created_collection = array(); $orders_created = 0; $products_created = 0; foreach ($_POST['customers'] as $cdata_raw) { $cdata = explode('|', $cdata_raw); $customer = $class_jc->retrieveDetail($cdata[0]); $ship_address = $class_jc->getAddress($cdata[1]); $bill_address = $class_jc->getAddress($cdata[2]); $order = array(); $order['jng_sp_id'] = $jng_sp_id; $order['xml_file'] = ''; $order['xml_date'] = 'null'; $order['iln_jng'] = 'null'; $order['iln_sp'] = 'null'; $order['sp_jng_id'] = ''; $order['order_date'] = $timestamp; $order['import_date'] = $timestamp; $order['shipment_id'] = $sp_detail['package_prefix'] . date('ymdhi') . '-' . str_pad($orders_created, 3, STR_PAD_LEFT); $order['order_id'] = $order['shipment_id']; $order['bill_id'] = 'null'; $order['gplcode'] = 'null';
function changeDeliveryAddress($jng_sp_orders_id, $title, $firstname, $lastname, $address, $address2, $city, $postcode, $country) { $order = $this->retrieveDetail($jng_sp_orders_id); use_class('jng_sp_customers'); $class_jc = new jng_sp_customers(); $customer = $class_jc->retrieveDetail(null, $order['jng_sp_id'], $order['customer_shipping_id']); $data = array(); $data['customer_title'] = $title; $data['customer_firstname'] = $firstname; $data['customer_lastname'] = $lastname; $data['address'] = $address; $data['address2'] = $address2; $data['city'] = $city; $data['postcode'] = $postcode; $data['country'] = $country; $class_jc->addAddress($customer['jng_sp_customers_id'], $data); $data = array(); $data['customer_shipping_title'] = $title; $data['customer_shipping_firstname'] = $firstname; $data['customer_shipping_lastname'] = $lastname; $data['customer_shipping_address'] = $address; $data['customer_shipping_address2'] = $address2; $data['customer_shipping_city'] = $city; $data['customer_shipping_postcode'] = $postcode; $data['customer_shipping_country'] = $country; tep_db_perform('jng_sp_orders', $data, 'update', "jng_sp_orders_id={$jng_sp_orders_id}"); }