tep_db_connect();
use_class('payone/financegateConnect');
use_class('jng_sp');
use_class('jng_sp_orders');
use_class('orders');
use_class('jng_sp_customers');
use_class('payone');
use_class('payone_invoice');
use_class('payone_logger');
use_class('minierp_customers');
$class_sp = new jng_sp();
$class_jo = new jng_sp_orders();
$class_o = new orders();
$class_jcust = new jng_sp_customers();
$class_cust = new minierp_customers();
$class_payone = new payone();
$payi = new payone_invoice();
$pi_gift_create = array();
$cut_off_orders_id = 20363;
$pi_gift_counter = 0;
$process_method = 'authorization';
$sets_of_invoice = $class_payone->retrieveList("invoice_complete_status = 'R' AND invoice_id = 139163");
//$sets_of_invoice =  $class_payone->retrieveList("invoice_id = 48");
//echo "<pre>";var_dump($sets_of_invoice);die();
$counter = 0;
if (count($sets_of_invoice) > 0) {
    $success = array();
    $failed = array();
    foreach ($sets_of_invoice as $invoice) {
        $counter++;
        $order_id = $invoice['invoice_order_id'];
예제 #2
0
 $return_qty = tep_db_prepare_input($_POST['return_qty']);
 $return_reason = tep_db_prepare_input($_POST['return_reason']);
 $comment_customer = tep_db_prepare_input(utf8_decode($_POST['comment_c']));
 $add2manpi = tep_db_prepare_input($_POST['add2manpi']);
 if ($comment_customer == $default_comment) {
     $comment_customer = '';
 }
 $comment_jng = tep_db_prepare_input(utf8_decode($_POST['comment_j']));
 if ($comment_jng == $default_comment) {
     $comment_jng = '';
 }
 $shipping_paid = tep_db_prepare_input($_POST['shipping_paid']);
 $return_id = $class_jo->returnItem($items_id, $return_date, $return_qty, $return_reason, $comment_customer, $comment_jng, $shipping_paid);
 //ADD OTTO.DE RETURN DATA TO PAYONE RETURN CONTAINER TABLE
 if ($return_id != '') {
     $class_payone = new payone();
     $class_payone->createReturnContainerSP($return_id, $return_qty, $items_id);
 }
 if ($add2manpi == 'true' && $comment_jng != '') {
     $products_id = $item['products_id'];
     $comment_by = $session_userinfo['username'];
     $comment_date = date('j-M-y H:i:s');
     $comment_text = $comment_jng;
     $comment_text_pi = "{$comment_by} [{$comment_date}]: {$comment_text}";
     tep_db_query("UPDATE products_non_configurator SET products_instruction=CONCAT(products_instruction, IF(products_instruction='', '', '\n\n'), '{$comment_text_pi}') WHERE products_id={$products_id}");
 }
 $result = array();
 $result['oi_id'] = $items_id;
 $result['new_status'] = 'NONE';
 ajaxReturn($result);
 exit;
<?php

#########################################
#  Author  : D3W4 & SAHAT               #
#  Created : Feb 22, 2010 11:33:43 AM   #
#########################################
global $db;
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
tep_db_connect();
use_class('orders');
use_class('jng_sp_orders');
use_class('payone');
$pay = new payone();
//RETRIEVE ALL INVOICES THAT ALREADY BEEN CREATED AND NOT YET SEND TO PAYONE
$sets_of_invoice = $pay->retrieveList("invoice_complete_status = '0' AND invoice_order_type IN ('S','J')");
$invoice_ids = array();
$invoice_ids_no_joid = array();
if (count($sets_of_invoice) > 0) {
    foreach ($sets_of_invoice as $invoice) {
        $invoice_id = $invoice['invoice_id'];
        $joid_arr = explode(",", $invoice['invoice_order_items_id']);
        if (count($joid_arr) > 0) {
            $ready_to_sent = true;
            foreach ($joid_arr as $joid) {
                if ($joid != '') {
                    $query = $invoice['invoice_order_type'] == 'S' ? "SELECT status FROM jng_sp_orders_items WHERE jng_sp_orders_items_id = {$joid} AND status IN (9,11)" : "SELECT status FROM orders_products WHERE orders_products_id = {$joid} AND status IN (9,11)";
                    $cek = tep_db_query($query);
                    //DENIED ALL STATUS EXCEPT 9/11
                    if (tep_db_num_rows($cek) == 0) {
<?php

#########################################
#  Author  : D3W4 & SAHAT               #
#  Created : Jun 14, 2010 10:02:01 AM   #
#########################################
global $db;
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
tep_db_connect();
use_class("payone");
use_class("payone_invoice");
$class_payone = new payone();
//CLEAN UP FOR STATUS 'P' THAT LONGER THAN 7 DAYS
/*
$q = "SELECT invoice_id FROM `payone_invoice_status_history`
   WHERE status = 'P'
   GROUP BY invoice_id
   HAVING DATEDIFF(CURDATE(), MAX(status_date)) > 7";
*
*/
$q = "SELECT invoice_id FROM payone_invoice WHERE invoice_complete_status = 'P' ORDER BY invoice_id";
$dbq = tep_db_query($q);
$counter = 0;
$arr_success = array();
$arr_failed = array();
while ($r = tep_db_fetch_array($dbq)) {
    $counter++;
    $invoice_id = $r['invoice_id'];
    $class_payi = new payone_invoice('invoice_id', $r['invoice_id']);
예제 #5
0
        //		switch($return_type) {
        //			case 'R':
        //			case 'W':
        //				$op = $class_o->retrieveProductDetail($opid);
        //				if($op['products_quantity']==$return_qty) {
        //					$class_o->updateProductStatus($opid, '1', $session_userinfo['username']);
        //					$sda_op = array('products_problem'=>$return_type);
        //					$class_o->updateOrderProductsDetail($opid, $sda_op);
        //				} else {
        //					$class_o->addReproductionDifQty($opid, $return_qty, $return_type);
        //				}
        //				break;
        //		}
        //                if($return_type=='C'){
        if ($return_id != '') {
            $class_payone = new payone();
            $class_payone->createReturnContainer($return_id, $return_qty, $opid);
        }
        //                }
        $result = array();
        $result['op_id'] = $opid;
        $result['new_status'] = '';
        ajaxReturn($result);
        exit;
    }
}
//START TEMPLATE
$content .= '<div>';
$content .= 'Search field ';
$content .= '<select id="osearch_field" name="search_field">';
$content .= '<option value="name">Customer Name</option>';
예제 #6
0
<?php

use_class('payone');
use_class('payone_invoice');
$class_payone = new payone();
//AJAX ACTION
if (isset($_POST['me_action'])) {
    if ($_POST['me_action'] == 'REFRESHCOUNTER') {
        $_SESSION['vars']['paging_page_clicked'] = 1;
        $status_counter = $class_payone->invoiceOverviewCounter();
        $result = array();
        foreach ($status_counter as $status => $counter) {
            $result[] = "{$status},{$counter}";
        }
        ajaxReturn($result);
        exit;
    } elseif ($_POST['me_action'] == 'SETPAIDATRIGACOLLECTED') {
        $payone_txid = $_POST['txid'];
        $btnid = $_POST['btnid'];
        $payi = new payone_invoice('payone_txid', $payone_txid);
        $payi->setPaidAtrigaCollected();
        $result = array();
        $result['btnid'] = $btnid;
        ajaxReturn($result);
        exit;
    } elseif ($_POST['me_action'] == 'CHECKCURRENTBALANCE') {
        $current_balance = 0;
        $info_balance = '';
        $id = $_POST['id'];
        $dbq = tep_db_query("SELECT * FROM payone_invoice WHERE payone_txid = '{$id}' OR invoice_id = '{$id}'");
        if (tep_db_num_rows($dbq) > 0) {
예제 #7
0
<?php

use_class('payone_logger');
$class_paylog = new payone_logger();
if (isset($_POST['me_action']) && $_POST['me_action'] != '') {
    if ($_POST['me_action'] == 'CANCELQUEUEDREFUND') {
        use_class('payone');
        $class_payone = new payone();
        $pkey_id = tep_db_prepare_input($_POST['pkeyid']);
        $status = str_replace('C', '', tep_db_prepare_input($_POST['type']));
        $class_payone->updateReturnStatus($pkey_id, $status);
        echo utf8_encode($pkey_id);
        exit;
    } elseif ($_POST['me_action'] == 'UPDATEINVOICE') {
        use_class('payone_invoice');
        $invoice_id = tep_db_prepare_input($_POST['invid']);
        $payi = new payone_invoice('invoice_id', $invoice_id);
        $field = tep_db_prepare_input($_POST['fld']);
        $value = tep_db_prepare_input($_POST['val']);
        if ($field == 'invoice_complete_status') {
            $value = trim(strtoupper($value));
        }
        $payi->updateField($field, $value);
        echo utf8_encode($field);
        exit;
    }
}
//DETAIL VIEW
if (isset($_GET['id']) && $_GET['id'] != '') {
    $id = tep_db_prepare_input($_GET['id']);
    $content = $class_paylog->retrieveDetail($id);
예제 #8
0
<?php

use_class('payone/financegateConnect');
use_class('jng_sp');
use_class('jng_sp_orders');
use_class('jng_sp_customers');
use_class('payone');
use_class('payone_invoice');
use_class('payone_logger');
$class_sp = new jng_sp();
$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]);
            }
        }
require_once '../functions.php';
require_once '../functions-2.php';
tep_db_connect();
use_class('payone/financegateConnect');
use_class('jng_sp');
use_class('jng_sp_orders');
use_class('orders');
use_class('jng_sp_customers');
use_class('minierp_customers');
use_class('payone');
use_class('payone_invoice');
use_class('payone_logger');
$class_sp = new jng_sp();
$class_jo = new jng_sp_orders();
$class_o = new orders();
$class_payone = new payone();
$class_jcust = new jng_sp_customers();
$class_cust = new minierp_customers();
$process_method = 'DEBIT';
//$sets_of_returns =  $class_payone->retrieveRefundSubmitReadyList("status = 0");
$pkey_ids = explode(',', tep_db_prepare_input($_GET['pkey_id']));
if (count($pkey_ids) > 0) {
    $pkey_ids = implode(',', $pkey_ids);
    $sets_of_returns = $class_payone->retrieveRefundList("status = 0 AND pkey_id IN (" . $pkey_ids . ")");
    $counter = 0;
    $counter_returns = 0;
    $counter_returns_no_txid = 0;
    $status_paid_complete = array('P', '1');
    //$counter_is_refund = 0;
    $counter_is_refund = array();
    if (count($sets_of_returns) > 0) {
예제 #10
0
 function updateProductStatus($items_id, $new_status, $updater = '', $cancelby = 'J', $add_to_prod_target = true)
 {
     /*==============================================================
       * PURPOSE  :   TO CHANGE PROCESS STATUS ORDER OF PRODUCTS
       * PARAMS   :   $items_id (NUMBER) >> e.g: 1234
       *              $new_status (NUMBER) >> e.g: 1
       *              $updater (STRING) "OPTIONAL" >> e.g: 'mbosse'
       *              $cancelby (STRING) "OPTIONAL" >> e.g: 'S'
       ===============================================================*/
     use_class('production_target');
     $pt = new production_target();
     list($new_status, $sub_status) = explode('-', $new_status);
     $item = $this->retrieveProductDetail($items_id);
     $itemMode = modeName($item['mode']);
     $timestamp = date('Y-m-d H:i:s');
     $is_reviving = statusIsCancelled($item['status']) && !statusIsCancelled($new_status);
     //Revive Item should move to in HH directly if other items are already in HH
     if ($is_reviving) {
         $item_others = $this->retrieveProducts($item['orders_id']);
         $others_in_hh = false;
         //If there's other items are already in HH set new status directly to HH
         foreach ($item_others as $io) {
             if ($io['status'] == '8') {
                 $new_status = '8';
                 $others_in_hh = true;
                 break;
             }
         }
         //If there's no items are already in HH (Full MTO)
         if (!$others_in_hh) {
             use_class('depot_orders');
             $class_do = new depot_orders();
             $item_do = $class_do->retrieveDetailTransmigran('JG', $items_id);
             if (!is_null($item_do)) {
                 if ($item_do['status'] < 6) {
                     /*  Order status is before in Package, do below steps:
                            1) Set real status same with last status of DP
                            2) Consider also set sub production status "only" when main status is in production
                            3) Cancel "directly" DP order, means we not use doCancelOrder
                         */
                     $new_status = $item_do['status'];
                     $sub_status = $new_status == '4' ? $item_do['prod_status'] : '';
                     $class_do->updateStatus($item_do['depot_orders_id'], '12', 'auto-set');
                     $reviving_need_next_update = true;
                     $revived_stock_status = $item_do['stock_status'];
                     $revived_mode = 'MTO';
                 } else {
                     /* Order status is >= "in Package"
                           1) Set real status to New
                        */
                     $new_status = '1';
                 }
             }
         }
     }
     //Only "Sent" and "Complete" status can be updated to "Returned"
     if ($new_status == '14' && !($item['status'] == '9' || $item['status'] == '11')) {
         return false;
     }
     //KPI Logging
     if ($add_to_prod_target) {
         if ($new_status == '5') {
             $pt->addDataToField($timestamp, 'finish', $item['products_quantity']);
         }
         if ($new_status == '6') {
             $pt->addDataToField($timestamp, 'package', $item['products_quantity']);
         }
         if ($new_status == '7') {
             $pt->addDataToField($timestamp, 'sent', $item['products_quantity']);
         }
         if ($new_status == '16') {
             $pt->addDataToField($timestamp, 'log_return_to_bali', $item['products_quantity']);
         }
         if ($new_status == '19') {
             $pt->addDataToField($timestamp, 'log_return_missing', $item['products_quantity']);
         }
         if ($new_status == '20') {
             $pt->addDataToField($timestamp, 'log_return_to_bin_in', $item['products_quantity']);
         }
         if ($new_status == '9') {
             $pt->addDataToField($timestamp, 'log_products_sent_b2c', $item['products_quantity']);
             if ($itemMode == 'DSO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_full_dso', $item['products_quantity']);
             } elseif ($itemMode == 'MTO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_full_mto', $item['products_quantity']);
             } elseif ($itemMode == 'WMO' || $itemMode == 'MMO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_mo', $item['products_quantity']);
             }
         }
     }
     //Update Status and create Status History
     $sda_op = array('status' => $new_status);
     $sda_op['status'] = $new_status;
     if ($new_status == '10') {
         $sda_op['products_problem'] = $cancelby;
     } elseif ($this->productStatusIsCancelled($item['status']) && !$this->productStatusIsCancelled($new_status)) {
         $sda_op['products_problem'] = '0';
     }
     $sub_status = trim(strtoupper($sub_status));
     if ($new_status == '4' && $sub_status != '') {
         $sda_op['prod_status'] = $sub_status;
     }
     //PS: please don't set empty prod_status when it updated to status > 4,
     //since this will used for check whether order could transferred to DP or not
     //when real order taken over by HH when it from production
     tep_db_perform('orders_products', $sda_op, 'update', "orders_products_id={$items_id}");
     $save_main_status_history = true;
     if (in_array($item['status'], array('3', '4', '5')) && $new_status == '4' && ($sub_status != '' && trim(strtoupper($item['prod_status'])) != $sub_status) || $is_reviving && $new_status == '4') {
         $psh = array();
         $psh['orders_items_id'] = $items_id;
         $psh['type'] = 'JG';
         $psh['status'] = $sub_status;
         $psh['status_quantity'] = $item['products_quantity'];
         $psh['status_date'] = $timestamp;
         $psh['update_by'] = $updater;
         saveProductionStatusHistory($psh);
         if ($item['status'] == '4') {
             $save_main_status_history = false;
         }
     }
     if ($save_main_status_history) {
         $sda = array();
         $sda['orders_products_id'] = $items_id;
         $sda['status'] = $new_status;
         $sda['status_quantity'] = $item['products_quantity'];
         $sda['status_date'] = $timestamp;
         $sda['update_by'] = $updater;
         tep_db_perform('orders_products_status_history', $sda);
     }
     //Revive Additional Action
     if ($is_reviving) {
         //Revive Items from Cancel Request Status
         $this->recalcProductsCounter($item['orders_id']);
         if ($new_status == '8') {
             $this->printCountReset($items_id);
             $this->updateOrderItemMode($items_id, 'MMO');
             use_class('depot_orders');
             $class_do = new depot_orders();
             $item_do = $class_do->transferFromRealOrder(SEGMENT_ID_HAMBURG, 'JG', $items_id);
             if ($item_do['status'] > 7) {
                 $class_do->updateStatus($item_do['depot_orders_id'], '1');
                 $class_do->printCountReset($item_do['depot_orders_id']);
             }
         }
         if ($reviving_need_next_update) {
             $this->updateProductStockStatus($items_id, $revived_stock_status);
             if ($revived_mode != '') {
                 $this->updateOrderItemMode($items_id, $revived_mode);
             }
         }
         //Set need repackaging flag if needed
         use_class('products_minierp');
         $class_pm = new products_minierp();
         $p_data = $class_pm->retrieveDetail($item['products_id'], 'p');
         if ($p_data['p']['need_repackaging'] == 1) {
             $this->setNeedRepackaging($item['orders_id']);
         }
     }
     //Check other available products of this order which need repackage "nr" on cancel
     if ($new_status == '10') {
         use_class('products_minierp');
         $class_pm = new products_minierp();
         $need_repackaging = false;
         $nr_q = "SELECT products_id FROM orders_products WHERE orders_id = {$item['orders_id']} AND status NOT IN (10, 12)" . " AND orders_products_id != {$items_id}";
         $nr_dbq = tep_db_query($nr_q);
         while ($nr_r = tep_db_fetch_array($nr_dbq)) {
             $p_data = $class_pm->retrieveDetail($nr_r['products_id'], 'p');
             if ($p_data['p']['need_repackaging'] == 1) {
                 $need_repackaging = true;
                 break;
             }
         }
         if (!$need_repackaging) {
             $this->resetNeedRepackaging($item['orders_id']);
         }
     }
     //Recalculate Orders Total, Products Counter on cancellation and reviving
     if ($new_status == '10' || $is_reviving) {
         $this->recalcTotals($item['orders_id']);
         $this->recalcProductsCounter($item['orders_id']);
         $this->recalcVouchersAndShippingCost($item['orders_id'], false);
     }
     //Update Stock Status and Elements Stock if necessary
     if ($new_status == '2' && $item['stock_status'] != 'S') {
         $this->updateProductStockStatus($items_id, false);
         $this->prodStatusReset($items_id);
         $this->eanPrintedReset($items_id);
         //$this->printCountReset($items_id);    //now we don't need to reset print_count for reprint pi when move to ready again.
     } elseif ($new_status == '3' && $item['stock_status'] == 'S' || $new_status == '4' && $item['stock_status'] == 'W') {
         $eu = $this->countElementsUsage($item['products_id'], $item['products_articles_id']);
         $jng_warehouses_id = '1';
         use_class('elements_stock');
         $class_es = new elements_stock();
         foreach ($eu as $elements_id => $euqty) {
             $reduce_amount = $item['products_quantity'] * $euqty;
             $class_es->reduceStockByPieces($jng_warehouses_id, $elements_id, $reduce_amount, 'RED JG-' . $items_id);
         }
         $this->updateProductStockStatus($items_id, 'R');
     } elseif ($new_status == '1') {
         //IF THERES ORDERS NEEDS RESET BACK TO NEW
         $this->printCountReset($items_id);
         $this->printConfirmReset($items_id);
         $this->prodStatusReset($items_id);
         $this->eanPrintedReset($items_id);
         $this->updateProductStockStatus($items_id, 0);
         $this->updateOrderItemMode($items_id, 'UNSET');
     }
     //Production Target Flag Counter
     if ($item['status'] == '1' && ($new_status == '2' || $new_status == '3')) {
         $this->productionTargetIn($timestamp, $item);
     } elseif ($new_status == '6') {
         $this->productionTargetOut($timestamp, $item);
     } elseif ($new_status == '10') {
         $this->productionTargetInReset($item);
     }
     //Auto Print PI rules
     if ($new_status == '3' || $new_status == '12') {
         $orders_id = $item['orders_id'];
         //$q_pi_status = tep_db_query("SELECT COUNT(1)=order_item_total AS pi_ready_to_print FROM orders_products WHERE orders_id = $orders_id AND status = 3 AND print_count = 0 GROUP BY orders_id");
         //ALSO CONSIDER GIFT/VOUCHER THAT DIRECTLY SET AS "SENT TO CUSTOMER" BUT print_count still zero
         $q_pi_status = tep_db_query("SELECT COUNT(1)=order_item_total AS pi_ready_to_print FROM orders_products WHERE orders_id = {$orders_id} AND status IN (3, 9) AND print_count = 0 GROUP BY orders_id");
         $pi_status = tep_db_fetch_array($q_pi_status);
         if ($pi_status['pi_ready_to_print'] == 1) {
             //PI PRINTED FOR THE FIRST TIME
             /* HANDLED BY BATCH PRINTING CRON cron/print-pi.php
                use_class('production_instruction_pdf');
                $class_pi = new production_instruction_pdf();
                $class_pi->addOrder('JG', $orders_id);
                $class_pi->createPDF(false, 'F', true);
                 */
         } else {
             if ($item['print_count'] > 0 && $item['print_confirmed'] > 0) {
                 //SECOND OR MORE PI PRINTED, could happen when there product by stock_status is "OK" but in real stock is "0" so this will set back to "NS". And when ready this will reprinted by using this block
                 $this->printConfirmReset($item['orders_products_id']);
                 $this->printCountReset($item['orders_products_id']);
                 /*
                                         use_class('production_instruction_pdf');
                                         $class_pi = new production_instruction_pdf();
                                         $class_pi->addItem('JG', $item['orders_products_id']);
                                         $class_pi->createPDF(false, 'F', false);    //not add to daily statistic, we consider this as not "NEW"
                 */
             }
         }
     }
     $q = tep_db_query("SELECT o.orders_id, o.orders_status, o.payment_method FROM orders_products op LEFT JOIN orders o ON o.orders_id=op.orders_id WHERE op.orders_products_id={$items_id}");
     $order = tep_db_fetch_array($q);
     if ($new_status == '12' || $item['products_problem'] == '0') {
         $status_to_update_orders = array('2' => '6', '4' => '5', '13' => '6', '5' => '7', '7' => '8', '9' => '10', '12' => '12');
         //cancelled
         if (array_key_exists($new_status, $status_to_update_orders)) {
             $changeorderstatus = true;
             if ($new_status == '12') {
                 //dont update order status if not all products are cancelled
                 if (!$this->isAllProductsCancelled($order['orders_id'])) {
                     $changeorderstatus = false;
                 }
             }
             if ($changeorderstatus) {
                 $order_new_status = $status_to_update_orders[$new_status];
                 if ($order['orders_status'] < $order_new_status) {
                     $this->updateOrderStatus($order['orders_id'], $order_new_status);
                 }
             }
         }
         if ($new_status == '12' && (strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_BANK_TRANSFER) || strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_PAYPAL))) {
             /*----------------------------------------------------------------------------------------
               * MAKE RETURN ENTRY FOR "PREPAYMENT ONLY" ON "CANCEL CONFIRM", SINCE FOR NON-PREPAYMENT, 
               * PAYONE INVOICE WILL CREATED WHEN PRODUCTS IS SENT, 
               * SO NO NEED TO ADJUST IT OR CREATE RETURN CONTAINER WHEN CANCEL CONFIRM PROCESS
               -----------------------------------------------------------------------------------------*/
             use_class('payone');
             use_class('payone_invoice');
             $class_payone = new payone();
             $payi = new payone_invoice('invoice_order_id', $order['orders_id'], "invoice_order_type = 'J'");
             if ($payi->isUncapturedPrePayment()) {
                 //UNCAPTURED PREAUTH VORKASSE NEED TO RECALCULATE INVOICE
                 $payi->recalculate();
                 //SET AS PAID WHEN OPEN BALANCE LEAVE SMALL AMOUNT OR THIS CANCEL PROCESS MAKES UNDERPAID BALANCE BECOMES PAID/OVERPAID
                 if ($payi->getBalance() * 100 <= PAYONE_MAX_RETURNED_OPEN_PAYMENT) {
                     $this->updatePaymentStatus($item['orders_id'], '1', 'auto-set');
                 }
             } else {
                 //AUTH VORKASSE, CAPTURED PREAUTH VORKASSE, PAYPAL ORDER WILL ADD TO RETURN CONTAINER
                 $class_payone->createReturnContainer('NULL', $item['products_quantity'], $items_id);
             }
         }
     }
     //NEED TO RECALCULATE INVOICE WHEN REVIVING UNCAPTURED PREAUTH VORKASSE
     if ($is_reviving && strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_PREPAYMENT)) {
         use_class('payone_invoice');
         $payi = new payone_invoice('invoice_order_id', $order['jng_sp_orders_id'], "invoice_order_type = 'S'");
         if ($payi->isUncapturedPrePayment()) {
             $payi->recalculate();
         }
     }
     //SET READY TO CAPTURED FOR PREPAYMENT PREAUTH THAT ALREADY SENT
     if ($new_status == '9' && strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_BANK_TRANSFER)) {
         use_class('payone_invoice');
         $payi = new payone_invoice('invoice_order_id', $item['orders_id'], "invoice_order_type = 'J'");
         $payi->setIsCaptured('2');
     }
     return $new_status;
 }
set_time_limit(0);
ini_set('memory_limit', '256M');
echo "<h1>START PROCESSING RETURNS</h1><br/>";
use_class('payone/financegateConnect');
use_class('jng_sp');
use_class('jng_sp_orders');
use_class('orders');
use_class('jng_sp_customers');
use_class('minierp_customers');
use_class('payone');
use_class('payone_invoice');
use_class('payone_logger');
$class_sp = new jng_sp();
$class_jo = new jng_sp_orders();
$class_o = new orders();
$class_payone = new payone();
$class_jcust = new jng_sp_customers();
$class_cust = new minierp_customers();
$process_method = 'DEBIT';
$filter_only_auth_or_captured_preauth = "(is_captured IS NULL OR is_captured NOT IN ('0','2'))";
// 1) OVERPAYMENT PROCESS-----------------------------------------------------------------------
$counter_overpayment = 0;
$counter_ovp_no_bankaccount = 0;
$counter_returns_no_txid = 0;
$non_returned_amount_overpayment = PAYONE_MIN_NON_RETURNED_OVERPAYMENT;
//5 EUR or less of overpayment won't returned
/*
 * FOR VORKASSE PRE-AUTH, THIS CRON WILL ONLY HANDLE FOR OVERPAID THAT COMES UP "AFTER" TRANSACTION IS CAPTURED
 * WHILE FOR OVERPAID THAT COMES UP BEFORE CAPTURED, REFUND WILL PROCESSED WHEN CAPTURED IS SENT (payone-pre-auth-capture.php)
 */
$sets_of_overpayment = $class_payone->retrieveList("invoice_complete_status = 'O' AND {$filter_only_auth_or_captured_preauth}");
tep_db_connect();
use_class('payone/financegateConnect');
use_class('jng_sp');
use_class('jng_sp_orders');
use_class('orders');
use_class('jng_sp_customers');
use_class('payone');
use_class('payone_invoice');
use_class('payone_logger');
use_class('minierp_customers');
$class_sp = new jng_sp();
$class_jo = new jng_sp_orders();
$class_o = new orders();
$class_jcust = new jng_sp_customers();
$class_cust = new minierp_customers();
$class_payone = new payone();
$payi = new payone_invoice();
$pi_gift_create = array();
$cut_off_orders_id = 20363;
$pi_gift_counter = 0;
//CREATE INVOICE FOR ORDER THAT ONLY CONTAIN PRODUCT OF FULL VOUCHER/GIFTS (JG ONLY)
$query = "SELECT o.orders_id, op.order_item_total FROM orders o";
$query .= " INNER JOIN orders_products op ON op.orders_id = o.orders_id AND op.status = 9";
$query .= " LEFT JOIN payone_invoice pi ON pi.invoice_order_type = 'J' AND pi.invoice_order_id = o.orders_id";
$query .= " WHERE op.products_model LIKE '%GIFT%'";
$query .= " AND pi.invoice_id IS NULL AND UPPER(o.payment_method) NOT IN (UPPER('" . PAYMENT_METHOD_BANK_TRANSFER . "'), UPPER('" . PAYMENT_METHOD_PAYPAL . "'))";
if ($cut_off_orders_id > 0) {
    $query .= " AND o.orders_id>{$cut_off_orders_id}";
}
$query .= " GROUP BY o.orders_id HAVING COUNT(o.orders_id) = op.order_item_total";
$q = tep_db_query($query);
예제 #13
0
 function updateItemStatus($items_id, $new_status, $updater = '', $cancelby = 'J', $add_to_prod_target = true)
 {
     use_class('production_target');
     $pt = new production_target();
     list($new_status, $sub_status) = explode('-', $new_status);
     $item = $this->retrieveItemDetail($items_id);
     $itemMode = modeName($item['mode']);
     $timestamp = date('Y-m-d H:i:s');
     $is_reviving = statusIsCancelled($item['status']) && !statusIsCancelled($new_status);
     $reviving_need_next_update = false;
     //Revive Item should move to in HH directly if other items are already in HH
     if ($is_reviving) {
         $item_others = $this->retrieveItems($item['jng_sp_orders_id']);
         $others_in_hh = false;
         //If there's other items are already in HH set new status directly to HH
         foreach ($item_others as $io) {
             if ($io['status'] == '8') {
                 $new_status = '8';
                 $others_in_hh = true;
                 break;
             }
         }
         //If there's no items are already in HH (Full MTO)
         if (!$others_in_hh) {
             use_class('depot_orders');
             $class_do = new depot_orders();
             $item_do = $class_do->retrieveDetailTransmigran('SP', $items_id);
             if (!is_null($item_do)) {
                 if ($item_do['status'] < 6) {
                     /*  Order status is before in Package, do below steps:
                            1) Set real status same with last status of DP
                            2) Consider also set sub production status "only" when main status is in production
                            3) Cancel "directly" DP order, means we not use doCancelOrder
                         */
                     $new_status = $item_do['status'];
                     $sub_status = $new_status == '4' ? $item_do['prod_status'] : '';
                     $class_do->updateStatus($item_do['depot_orders_id'], '12', 'auto-set');
                     $reviving_need_next_update = true;
                     $revived_stock_status = $item_do['stock_status'];
                     $revived_mode = 'MTO';
                 } else {
                     /* Order status is >= "in Package"
                           1) Set real status to New
                        */
                     $new_status = '1';
                 }
             }
         }
     }
     //Only "Sent" and "Complete" status can be updated to "Returned"
     if ($new_status == '14' && !($item['status'] == '9' || $item['status'] == '11')) {
         return false;
     }
     //KPI Logging
     if ($add_to_prod_target) {
         if ($new_status == '5') {
             $pt->addDataToField($timestamp, 'finish', $item['order_quantity']);
         }
         if ($new_status == '6') {
             $pt->addDataToField($timestamp, 'package', $item['order_quantity']);
         }
         if ($new_status == '7') {
             $pt->addDataToField($timestamp, 'sent', $item['order_quantity']);
         }
         if ($new_status == '16') {
             $pt->addDataToField($timestamp, 'log_return_to_bali', $item['order_quantity']);
         }
         if ($new_status == '19') {
             $pt->addDataToField($timestamp, 'log_return_missing', $item['order_quantity']);
         }
         if ($new_status == '20') {
             $pt->addDataToField($timestamp, 'log_return_to_bin_in', $item['order_quantity']);
         }
         if ($new_status == '9') {
             use_class('jng_sp');
             $class_jsp = new jng_sp();
             //Get Sales Partner B2B
             $sp_b2b = array_keys($class_jsp->retrieveList("sp_type = 1"));
             $item_orders = $this->retrieveDetail($item['jng_sp_orders_id']);
             if (in_array($item_orders['jng_sp_id'], $sp_b2b)) {
                 $pt->addDataToField($timestamp, 'log_products_sent_b2b', $item['order_quantity']);
             } else {
                 $pt->addDataToField($timestamp, 'log_products_sent_b2c', $item['order_quantity']);
             }
             if ($itemMode == 'DSO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_full_dso', $item['order_quantity']);
             } elseif ($itemMode == 'MTO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_full_mto', $item['order_quantity']);
             } elseif ($itemMode == 'WMO' || $itemMode == 'MMO') {
                 $pt->addDataToField($timestamp, 'log_products_sent_mo', $item['order_quantity']);
             }
         }
     }
     $sub_status = trim(strtoupper($sub_status));
     if ($updater != 'new-import') {
         $setcancelation = $item['status'] == '10' && $new_status != '12' ? ", cancel_status=NULL" : '';
         if ($new_status == '10') {
             $setcancelation = ", cancel_status='{$cancelby}'";
         }
         $set_prod_status = $new_status == '4' && $sub_status != '' ? ", prod_status = '" . $sub_status . "'" : '';
         //PS: please don't set empty prod_status when it updated to status > 4,
         //since this will used for check whether order could transferred to DP or not
         //when real order taken over by HH when it from production
         tep_db_query("UPDATE jng_sp_orders_items SET status='{$new_status}' {$setcancelation} {$set_prod_status} WHERE jng_sp_orders_items_id={$items_id}");
     }
     $save_main_status_history = true;
     if (in_array($item['status'], array('3', '4', '5')) && $new_status == '4' && ($sub_status != '' && trim(strtoupper($item['prod_status'])) != $sub_status) || $is_reviving && $new_status == '4') {
         $psh = array();
         $psh['orders_items_id'] = $items_id;
         $psh['type'] = 'SP';
         $psh['status'] = $sub_status;
         $psh['status_quantity'] = $item['order_quantity'];
         $psh['status_date'] = $timestamp;
         $psh['update_by'] = $updater;
         saveProductionStatusHistory($psh);
         if ($item['status'] == '4') {
             $save_main_status_history = false;
         }
     }
     if ($save_main_status_history) {
         $sda = array();
         $sda['jng_sp_orders_items_id'] = $items_id;
         $sda['status'] = $new_status;
         $sda['status_quantity'] = $item['order_quantity'];
         $sda['status_date'] = $timestamp;
         $sda['update_by'] = $updater;
         tep_db_perform('jng_sp_orders_items_status_history', $sda);
     }
     if ($is_reviving) {
         //Revive Items from Cancel Request Status
         $this->recalculateOrderItemCount(null, $items_id);
         if ($new_status == '8') {
             $this->printCountReset($items_id);
             $this->updateOrderItemMode($items_id, 'MMO');
             use_class('depot_orders');
             $class_do = new depot_orders();
             $item_do = $class_do->transferFromRealOrder(SEGMENT_ID_HAMBURG, 'SP', $items_id);
             $do_close_status = explode(',', depot_orders::FILTER_STATUS_CLOSE);
             if (in_array($item_do['status'], $do_close_status)) {
                 $class_do->updateStatus($item_do['depot_orders_id'], '1');
                 $class_do->printCountReset($item_do['depot_orders_id']);
             }
         }
         if ($reviving_need_next_update) {
             $this->updateItemStockStatus($items_id, $revived_stock_status);
             if ($revived_mode != '') {
                 $this->updateOrderItemMode($items_id, $revived_mode);
             }
         }
         //Set need repackaging flag if needed
         $class_pm = new products_minierp();
         $p_data = $class_pm->retrieveDetail($item['products_id'], 'p');
         if ($p_data['p']['need_repackaging'] == 1) {
             $this->setNeedRepackaging($item['jng_sp_orders_id']);
         }
     }
     //Check other available products of this order which need repackage "nr" on cancel
     if ($new_status == '10') {
         $class_pm = new products_minierp();
         $need_repackaging = false;
         $nr_q = "SELECT products_id FROM jng_sp_orders_items WHERE jng_sp_orders_id = {$item['jng_sp_orders_id']} AND status NOT IN (10, 12)" . " AND jng_sp_orders_items_id != {$items_id}";
         $nr_dbq = tep_db_query($nr_q);
         while ($nr_r = tep_db_fetch_array($nr_dbq)) {
             $p_data = $class_pm->retrieveDetail($nr_r['products_id'], 'p');
             if ($p_data['p']['need_repackaging'] == 1) {
                 $need_repackaging = true;
                 break;
             }
         }
         if (!$need_repackaging) {
             $this->resetNeedRepackaging($item['jng_sp_orders_id']);
         }
     }
     //Update Stock Status and Elements Stock if necessary
     if ($new_status == '2' && $item['stock_status'] != 'S' && $item['stock_status'] != 'W') {
         //Set stock status to need sourcing if item is move to sourcing tab
         $this->updateItemStockStatus($items_id, false);
         $this->prodStatusReset($items_id);
         $this->eanPrintedReset($items_id);
         //$this->printCountReset($items_id);    //now we don't need to reset print_count for reprint pi when move to ready again.
         //TODO: Ceck if above statement is still true with new batch pi printing
     } elseif ($new_status == '3' && $item['stock_status'] == 'S' || $new_status == '4' && $item['stock_status'] == 'W') {
         //Reduce elements stock when products are forced to move to ready/production before approved by elements stock check
         $eu = $this->countElementsUsage($item['products_id'], $item['products_articles_id']);
         if (count($eu) > 0) {
             $jng_warehouses_id = '1';
             use_class('elements_stock');
             $class_es = new elements_stock();
             foreach ($eu as $elements_id => $euqty) {
                 $reduce_amount = $item['order_quantity'] * $euqty;
                 $class_es->reduceStockByPieces($jng_warehouses_id, $elements_id, $reduce_amount, 'RED SP-' . $items_id);
             }
         }
         $this->updateItemStockStatus($items_id, 'R');
     } elseif ($new_status == '1') {
         //IF THERES ORDERS NEEDS RESET BACK TO NEW
         $this->printCountReset($items_id);
         $this->printConfirmReset($items_id);
         $this->prodStatusReset($items_id);
         $this->eanPrintedReset($items_id);
         $this->updateItemStockStatus($items_id, 0);
         $this->updateOrderItemMode($items_id, 'UNSET');
     }
     //Production Target Flag Counter
     if ($item['status'] == '1' && ($new_status == '2' || $new_status == '3')) {
         //TODO: Move TARGET IN TO WHEN PI IS CONFIRMED BY SCANNING IT FOR EAN LABEL
         $this->productionTargetIn($timestamp, $item);
     } elseif ($new_status == '6') {
         $this->productionTargetOut($timestamp, $item);
     } elseif ($new_status == '10') {
         $this->productionTargetInReset($item);
     }
     //Auto Print PI rules
     if ($new_status == '3' || $new_status == '12') {
         /* e.g. :
                    5 items ordered > 4 to ready, 1 to sourcing ( PI not printed yet )
                    so this block is for handling PI not printed when "1 sourcing" is cancelled, while print_count flag is still "0"
             * !!!ABOVE SAMPLE PROCESS ISN'T RELIABLE AGAIN, SINCE WE NOW CHANGE PRINT PI DIRECTLY WHEN IT MOVES TO READY TAB VIA CRON cron/print-pi.php!!!
            */
         $jng_sp_orders_id = $item['jng_sp_orders_id'];
         $q_pi_status = tep_db_query("SELECT COUNT(1)=order_item_total AS pi_ready_to_print FROM jng_sp_orders_items WHERE jng_sp_orders_id = {$jng_sp_orders_id} AND status = 3 AND print_count = 0 GROUP BY jng_sp_orders_id");
         $pi_status = tep_db_fetch_array($q_pi_status);
         if ($pi_status['pi_ready_to_print'] == 1) {
             //PI PRINTED FOR THE FIRST TIME
             /* HANDLED BY BATCH PRINTING CRON cron/print-pi.php
                use_class('production_instruction_pdf');
                $class_pi = new production_instruction_pdf();
                $class_pi->addOrder('SP', $jng_sp_orders_id);
                $class_pi->createPDF(false, 'F', true);
                 */
         } else {
             if ($item['print_count'] > 0 && $item['print_confirmed'] > 0) {
                 //SECOND OR MORE PI PRINTED, could happen when there product by stock_status is "OK" but in real stock is "0" so this will set back to "NS". And when ready this will reprinted by using this block
                 //reset print_count and print_confirmed to include this order again on next print-pi scheduler
                 $this->printConfirmReset($item['jng_sp_orders_items_id']);
                 $this->printCountReset($item['jng_sp_orders_items_id']);
                 /*
                                     use_class('production_instruction_pdf');
                                     $class_pi = new production_instruction_pdf();
                                     $class_pi->addItem('SP', $item['jng_sp_orders_items_id']);
                                     $class_pi->createPDF(false, 'F', false);    //not add to daily statistic, we consider this as not "NEW"
                 */
             }
         }
     }
     $q = tep_db_query("SELECT jo.jng_sp_orders_id, UPPER(jo.payment_method) AS payment_method FROM jng_sp_orders_items joi LEFT JOIN jng_sp_orders jo ON jo.jng_sp_orders_id=joi.jng_sp_orders_id WHERE joi.jng_sp_orders_items_id={$items_id}");
     $order = tep_db_fetch_array($q);
     if ($new_status == '12' && strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_PREPAYMENT)) {
         /*----------------------------------------------------------------------------------------
           * MAKE RETURN ENTRY FOR "PREPAYMENT ONLY" ON "CANCEL CONFIRM", SINCE FOR NON-PREPAYMENT, 
           * PAYONE INVOICE WILL CREATED WHEN PRODUCTS IS SENT, 
           * SO NO NEED TO ADJUST IT OR CREATE RETURN CONTAINER WHEN CANCEL CONFIRM PROCESS
           -----------------------------------------------------------------------------------------*/
         use_class('payone');
         use_class('payone_invoice');
         $class_payone = new payone();
         $payi = new payone_invoice('invoice_order_id', $order['jng_sp_orders_id'], "invoice_order_type = 'S'");
         if ($payi->isUncapturedPrePayment()) {
             //UNCAPTURED PREAUTH PREPAYMENT NEED TO RECALCULATE INVOICE
             $payi->recalculate();
             //SET AS PAID WHEN OPEN BALANCE LEAVE SMALL AMOUNT OR THIS CANCEL PROCESS MAKES UNDERPAID BALANCE BECOMES PAID/OVERPAID
             if ($payi->getBalance() * 100 <= PAYONE_MAX_RETURNED_OPEN_PAYMENT) {
                 $this->updatePaymentStatus($item['jng_sp_orders_id'], '1', 'auto-set');
             }
         } else {
             //AUTH PREPAYMENT, CAPTURED PREAUTH PREPAYMENT (ADD TO RETURN CONTAINER)
             $class_payone->createReturnContainerSP('NULL', $item['order_quantity'], $items_id);
         }
     }
     //NEED TO RECALCULATE INVOICE WHEN REVIVING UNCAPTURED PREAUTH PREPAYMENT
     if ($is_reviving && strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_PREPAYMENT)) {
         use_class('payone_invoice');
         $payi = new payone_invoice('invoice_order_id', $order['jng_sp_orders_id'], "invoice_order_type = 'S'");
         if ($payi->isUncapturedPrePayment()) {
             $payi->recalculate();
         }
     }
     //SET READY TO CAPTURED FOR PREPAYMENT PREAUTH THAT ALREADY SENT
     if ($new_status == '9' && strtoupper($order['payment_method']) == strtoupper(PAYMENT_METHOD_PREPAYMENT)) {
         use_class('payone_invoice');
         $payi = new payone_invoice('invoice_order_id', $item['jng_sp_orders_id'], "invoice_order_type = 'S'");
         $payi->setIsCaptured('2');
     }
     return $new_status;
 }
#########################################
#  Author  : D3W4                       #
#  Created : Mar 1, 2010 12:19:26 PM    #
#########################################
global $db;
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
tep_db_connect();
use_class('jng_sp');
use_class('jng_sp_orders');
use_class('payone');
use_class('payone_invoice');
$class_sp = new jng_sp();
$class_jo = new jng_sp_orders();
$class_payone = new payone();
$class_pi = new payone_invoice();
$sets_of_returns = $class_payone->retrieveRefundList("status = 0");
//TODO : ALSO INCLUDE ALL OVERPAYMENT FROM payone_invoice WITH invoice_complete_status = 'O'
if (count($sets_of_returns) > 0) {
    #echo "<pre>";var_dump($sets_of_returns);
    foreach ($sets_of_returns as $returns) {
        $joi_id = $returns['jng_sp_orders_items_id'];
        $amount_return = round($returns['amount']);
        $invoice_id = $returns['invoice_id'];
        $payi = $class_payone->retrieveList("invoice_id = {$invoice_id}");
        #echo "<pre>";var_dump($payi);
        if (count($payi > 0)) {
            $amount = round($payi[0]['invoice_amount'] * 100);
            $amount_paid = round($payi[0]['invoice_amount_paid'] * 100);
            $amount_cancel = round($payi[0]['invoice_amount_cancel'] * 100);
<?php

global $db;
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
tep_db_connect();
use_class('jng_sp_customers');
use_class('payone');
use_class('jng_sp_orders');
use_class('payone_invoice');
$class_payone = new payone();
$class_pi = new payone_invoice();
$class_jcust = new jng_sp_customers();
$class_jo = new jng_sp_orders();
$data_return_no_container = array();
$data_return_poa = array();
$data_return_cod = array();
//-----------HAVE RETURN (FULL) WITHOUT RETURN CONTAINER
$query = "SELECT d.shipping_costs,d.cod_costs,d.`payment_method`,a.`return_id`, a.return_quantity, c.payone_txid, c.invoice_id, b.jng_sp_orders_id, b.`jng_sp_orders_items_id`, b.article_number,b.billing_text,b.price\nFROM jng_sp_orders_items_return a,`jng_sp_orders_items` b, payone_invoice c, `jng_sp_orders` d\nWHERE a.jng_sp_orders_items_id\nIN (\nSELECT invoice_order_items_id\nFROM payone_invoice\nWHERE invoice_order_id\nIN ( 17334, 17237, 16476, 17038, 16819, 16486, 16672, 16473, 16732, 16581, 16493, 17250, 16854, 16483, 16582, 16508, 17182, 17045, 16766, 16513, 16666, 16836, 16757, 16485, 16866, 16583, 16490 )\n)\nand a.`jng_sp_orders_items_id` = b.jng_sp_orders_items_id\nand c.invoice_order_id = b.jng_sp_orders_id\nand d.`jng_sp_orders_id` = b.`jng_sp_orders_id`";
$res = tep_db_query($query);
$result = array();
if (tep_db_num_rows($res) > 0) {
    while ($row = tep_db_fetch_array($res)) {
        $result[] = $row;
    }
}
//echo"<pre>";var_dump($result);die();
foreach ($result as $data) {
    //    echo"<pre>";var_dump($data);die();
    $invoice_id = $data['invoice_id'];
<?php

/**
 * Description of payment-overview-orders
 * @author IT TEAM BONOFACTUM
 * @created Mar 14, 2015 3:07:25 PM 
 */
use_class('payone');
$invoice_date_start = date('Y-m-d 00:00:00', strtotime(tep_db_prepare_input($_GET['ids'])));
$invoice_date_end = date('Y-m-d 23:59:59', strtotime(tep_db_prepare_input($_GET['ide'])));
$filter = "invoice_date >= '{$invoice_date_start}' AND invoice_date <= '{$invoice_date_end}'";
$payment_summary_data = payone::getPaymentSummaryData('A', $filter);
$content = 'Invoice Date from ' . date('d-m-Y', strtotime($invoice_date_start));
$content .= '&nbsp;&nbsp;to ' . date('d-m-Y', strtotime($invoice_date_end));
if (count($payment_summary_data) > 0) {
    $table = array();
    $th = array();
    $th['d'] = 'Invoice<br/>Date';
    $th['d2'] = 'Invoice<br/>Due Date';
    $th['c'] = 'Customer Name';
    $th['o'] = 'Payment<br/>Method';
    $th['id2'] = 'Order No';
    $th['id3'] = 'Payone<br/>txid';
    $th['p'] = 'Saldo<br/>(EUR)';
    $table[] = $th;
    foreach ($payment_summary_data as $dt) {
        $tr = array();
        $tr['d'] = date('d-m-Y', strtotime($dt['invoice_date']));
        $tr['d2'] = date('d-m-Y', strtotime($dt['invoice_due_date']));
        $tr['c'] = $dt['customers_name'];
        $tr['o'] = $dt['payment_method'];
function processReturnOld($sp_type, $order_id, $ean_code, $reason = '0')
{
    global $class_jo;
    global $class_o;
    use_class('payone');
    use_class('products_minierp');
    $class_payone = new payone();
    $class_pm = new products_minierp();
    $return_allowed_status = array('9', '11', '16', '20');
    $is_best_product = '';
    $order_product_id = '';
    $product_barcode = '';
    $status = 'RETURNNOTALLOWED';
    if (strtolower($sp_type) == 's') {
        $items = $class_jo->retrieveItems($order_id);
        foreach ($items as $key => $item) {
            $items_id = $item['jng_sp_orders_items_id'];
            $product_code = $item['products_model'];
            $product_name = $item['products_name'];
            //            echo $item['products_ean']." | ".$item['status']."<br/>";
            if ($item['products_ean'] == $ean_code && in_array($item['status'], $return_allowed_status)) {
                $products_id = $item['products_id'];
                //                if($reason=='') {
                //                    $order_product_id = $items_id;
                //                    $status = 'MCSCANREASON';
                //                    $reasons = $class_jo->returnReasonList();
                //                    $reasons_list = array();
                //                    foreach($reasons as $reason_id=>$val){
                //                        $reasons_list[] = $reason_id."-".$val;
                //                    }
                //                    $result['reasons'] = $reasons_list;
                //                }else{
                $returnable = $item['order_quantity'];
                $return_data = $class_jo->retrieveReturnItem($items_id);
                //                    echo "<pre>";var_dump($return_data);
                if (!is_null($return_data)) {
                    foreach ($return_data as $rd) {
                        $returnable -= $rd['return_quantity'];
                    }
                }
                if ($returnable > 0) {
                    $order_product_id = $items_id;
                    $product_barcode = "SP-{$order_product_id}";
                    $is_best_product = $class_pm->isBestProduct($item['products_id']);
                    $status = $is_best_product ? 'MCBINORRETURN' : 'MCRETURNTOBALI';
                    //CREATE RETURN
                    $return_date = date('Y-m-d H:i:s');
                    $return_qty = 1;
                    $comment_customer = '';
                    $comment_jng = '';
                    $shipping_paid = tep_db_prepare_input($_POST['shipping_paid']);
                    $return_id = $class_jo->returnItem($items_id, $return_date, $return_qty, $reason, $comment_customer, $comment_jng, $shipping_paid);
                    //CREATE PAYONE RETURN
                    //                        $return_id = '123';
                    if ($return_id != '') {
                        $class_payone->createReturnContainerSP($return_id, $return_qty, $items_id);
                        $items_q = tep_db_query("SELECT SUM(order_quantity) AS total FROM jng_sp_orders_items WHERE jng_sp_orders_id={$order_id} AND status NOT IN (10, 12)");
                        $items = tep_db_fetch_array($items_q);
                        $items_total = $items['total'];
                        $returns_total = getTotalReturnOrderSP($order_id);
                        $returnable = $items_total - $returns_total;
                    }
                }
                //                } //BLOCK reason status
            }
        }
    } elseif (strtolower($sp_type) == 'j') {
        use_class('products_ean');
        $class_pean = new products_ean();
        $items = $class_o->retrieveProducts($order_id);
        foreach ($items as $key => $item) {
            $ean = $class_pean->getEAN($item['products_id'], $item['products_articles_id']);
            $opid = $item['orders_products_id'];
            $product_code = $item['products_model'];
            $product_name = $item['products_name'];
            //            echo $ean." | ".$item['status']."<br/>";
            if ($ean == $ean_code && in_array($item['status'], $return_allowed_status)) {
                $products_id = $item['products_id'];
                $existing_return = $class_o->productReturnTotalQty($opid);
                if ($existing_return < $item['products_quantity']) {
                    $order_product_id = $opid;
                    $product_barcode = "JG-{$order_product_id}";
                    $is_best_product = $class_pm->isBestProduct($item['products_id']);
                    $status = $is_best_product ? 'MCBINORRETURN' : 'MCRETURNTOBALI';
                    //CREATE RETURN
                    $opid = $item['orders_products_id'];
                    $return_date = date('Y-m-d H:i:s');
                    $return_qty = 1;
                    $return_type = 'C';
                    $return_status = '0';
                    $return_comment = '';
                    $product_received = 1;
                    $return_id = $class_o->addReturnProduct($opid, $return_date, $return_qty, $return_type, $return_status, $return_comment, $product_received);
                    //CREATE PAYONE RETURN
                    //                    $return_id = '123';
                    if ($return_id != '') {
                        $class_payone->createReturnContainer($return_id, $return_qty, $opid);
                        $items_q = tep_db_query("SELECT SUM(products_quantity) AS total FROM orders_products WHERE orders_id={$order_id}  AND status NOT IN (10, 12)");
                        $items = tep_db_fetch_array($items_q);
                        $items_total = $items['total'];
                        $returns_total = getTotalReturnOrderJG($order_id);
                        $returnable = $items_total - $returns_total;
                    }
                }
            }
        }
    }
    $result['product_barcode'] = $product_barcode;
    $result['order_product_id'] = $order_product_id;
    $result['eancode'] = $ean_code;
    if ($products_id != '') {
        $result['product_id'] = $products_id;
        $qp = "SELECT p.*, pd.products_name FROM products p INNER JOIN products_description pd ON p.products_id = pd.products_id\n                WHERE p.products_id = {$products_id} AND pd.language_id = 2";
        $dbqp = tep_db_query($qp);
        $rp = tep_db_fetch_array($dbqp);
        $result['product_code'] = $rp['products_model'];
        $result['product_name'] = $rp['products_name'];
        $result['product_image'] = webImageSource($rp['products_image'], '80');
        //'http://www.julie-grace.de/images/imagecache/500x500_03601033.jpg';
    }
    $result['returnable'] = $returnable;
    $result['status'] = $status;
    return $result;
}
<?php

global $db;
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
tep_db_connect();
$type = tep_db_prepare_input($_GET['type']);
$items = explode(',', tep_db_prepare_input($_GET['items']));
if (count($items) > 0) {
    use_class('payone');
    $class_payone = new payone();
    $return_ids = array();
    foreach ($items as $item_id) {
        if (strtoupper($type) == 'J') {
            $dbq = tep_db_query("SELECT products_quantity AS quantity FROM orders_products WHERE orders_products_id = '{$item_id}'");
        } elseif (strtoupper($type) == 'S') {
            $dbq = tep_db_query("SELECT order_quantity AS quantity FROM jng_sp_orders_items WHERE jng_sp_orders_items_id = '{$item_id}'");
        }
        $item = tep_db_fetch_array($dbq);
        $return_ids[] = $class_payone->createReturnContainer('NULL', $item['quantity'], $item_id);
    }
    echo "Return created > (" . implode(',', $return_ids) . ")";
}
##  USED          :   FOR CHECKING RELIABILTY OF PAYONE CUSTOMERS           #
##  PARAMETERS    :   jng_sp_orders_id                                      #
#############################################################################
   
$result_test = $class_payone->payoneCustomerBankAccountCheck('6806');//14876
$result_test = $class_payone->payoneCustomerAddressCheck('20820');
$result_test = $class_payone->payoneCustomerConsumerScore('6806');
*/
set_time_limit(0);
global $db;
require_once '../confy.php';
require_once '../functions.php';
require_once '../functions-2.php';
tep_db_connect();
use_class('payone');
$class_payone = new payone();
$q = "SELECT DISTINCT pr.`reminder_level`, o.`jng_sp_orders_id`,o.customer_billing_address, c.* FROM `payone_invoice` p\nINNER JOIN `payone_reminder` pr ON pr.invoice_id = p.invoice_id\nINNER JOIN `jng_sp_orders` o ON o.`jng_sp_orders_id` = p.`invoice_order_id`\nINNER JOIN `jng_sp_customers` c ON c.`customer_id` = o.`customer_billing_id`\nWHERE pr.`reminder_level` = (SELECT reminder_level FROM payone_reminder WHERE invoice_id = p.invoice_id and reminder_level in ('5','A') ORDER BY info_received DESC LIMIT 1)\nAND o.`jng_sp_id` = 2\nand c.jng_sp_customers_id not in (14402,14433)\norder by c.customer_firstname";
$dbq = tep_db_query($q);
echo "<table border='1'>\n    <tr>\n        <td><b>NO.</b></td>\n        <td><b>REMINDER LEVEL</b></td>\n        <td><b>ORDERS ID</b></td>\n        <td><b>FIRSTNAME</b></td>\n        <td><b>LASTNAME</b></td>\n        <td><b>ADDRESS</b></td>\n        <td><b>BAC</b></td>\n        <td><b>AC</b></td>\n        <td><b>CS</b></td>\n    </tr>";
$n = 0;
$bac = null;
$ac = null;
$cs = null;
while ($r = tep_db_fetch_array($dbq)) {
    $order_id = $r['jng_sp_orders_id'];
    $n++;
    echo "<tr>";
    echo "<td>{$n}</td>";
    echo "<td>{$r['reminder_level']}</td>";
    echo "<td>{$r['jng_sp_orders_id']}</td>";
    echo "<td>{$r['customer_firstname']}</td>";