Example #1
0
 private static function parserCsvFiles($downloadFilePath)
 {
     $header = NULL;
     $data = array();
     if (($handle = fopen($downloadFilePath, 'r')) !== FALSE) {
         while (($row = fgetcsv($handle, 1000, ',')) !== FALSE) {
             if (!$header) {
                 $header = $row;
             } else {
                 $data[] = array_combine($header, $row);
             }
         }
         fclose($handle);
     }
     $db = SafeMySQL::getInstance();
     echo '<pre>';
     print_r($db->getConn());
     echo '</pre>';
     foreach ($data as $orderArray) {
         if (isset($orderArray['Tracking Number']) && isset($orderArray['Order Id'])) {
             /*
              * Old query
             $sql = "UPDATE `orders` SET `tracking_number`=?s, `status`='shipped'
                     WHERE (`order_id`=?i OR `ship_with`=?i) AND `status` = 'sent'";
             */
             $sql = "UPDATE `packages_orders` AS `po`\n                    JOIN `packages` AS `p` USING (`package_id`)\n                    LEFT JOIN `orders` AS `o` ON `o`.`order_id` = `po`.`order_id` AND `o`.`status` IN ('ok', 'sent')\n                    SET `p`.`tracking_number` = ?s, `o`.`status` = 'shipped'\n                    WHERE `package_id` =\n                    (SELECT `package_id` FROM `packages_orders` AS `p1` WHERE `p1`.`order_id`=?i LIMIT 1)";
             $orderID = (int) $orderArray['Order Id'];
             echo $sql . '<hr>';
             $db->query($sql, $orderArray['Tracking Number'], $orderID);
             if ($db->affectedRows() > 0) {
                 Event::setEvents($orderID, 9);
                 OrderLog::createLog(0, $orderID, 20);
             }
         }
     }
 }
Example #2
0
 public static function finalizeOrder($orderID)
 {
     $modelOrder = Order::model()->findByPk((int) $orderID);
     if (!$modelOrder) {
         return false;
     }
     //Check status
     $modelAttempt = new Attempt();
     $modelAttempt->getLastOrderAttempt($modelOrder->order_id, Attempt::DEBIT_TYPE);
     if (in_array($modelAttempt->status, array(Attempt::SUCCESS_STATUS, Attempt::DECLINED_STATUS))) {
         return true;
     }
     $payment = new PaymentAPI();
     $response = $payment->updateStatusAttempt($modelAttempt);
     if ($response->attemptStatus == 'success') {
         $modelOrder->status = Order::STATUS_OK;
         $modelOrder->removeFlags(Order::FlAG_PAY);
         $modelOrder->addFlags(Order::FlAG_PAID);
         $modelOrder->payment_total = $modelAttempt->amount;
         $modelOrder->save();
         Event::setEvents($modelOrder->order_id, 8, false);
         //update recurring_next
         $sql = "UPDATE `orders_products`\n                JOIN `products` USING(`product_id`)\n                SET `orders_products`.`recurring_next` = DATE_ADD(NOW(), INTERVAL `products`.`subscription_days` DAY)\n                WHERE FIND_IN_SET('recurring', `orders_products`.`flags`)>0\n                AND `orders_products`.`order_id`=?i";
         self::$_msql->query($sql, $modelOrder->order_id);
         if ($modelOrder->billing_cycle == 0) {
             // Delete order prospect
             Prospects::deleteProspectOkOrder($modelOrder->order_id);
             Orders::createAttachedOrders($modelOrder);
             // Fire Pixel
             $cloneOrder = clone $modelOrder;
             Pixel::firePixelPb($cloneOrder);
             unset($cloneOrder);
         }
     } elseif ($response->attemptStatus == 'declined') {
         $modelOrder->status = Order::STATUS_ERROR;
         $modelOrder->removeFlags(Order::FlAG_PAY);
         $modelOrder->save();
         // Delete order prospect
         Prospects::deleteProspectOkOrder($modelOrder->order_id);
     }
 }
Example #3
0
         $orderModel->addFlags('paid');
         $orderModel->payment_total = $paymentResponse->attemptModel->amount;
     } else {
         // was the payment accepted by the gateway, but not actually processed?
         $orderModel->removeFlags('pay');
         if (!$orderModel->flags) {
             $orderModel->flags = '';
         }
         // if flags == NULL then save() will not work!
     }
     //$order->updated = date("Y-m-d H:i:s");
     if (!$orderModel->save(true, null, false)) {
         //this should never happen.  just log the error, email the team and assume its all good for the customer
         fb($orderModel->getErrors());
     }
     Event::setEvents($orderModel->order_id, 8, false);
     //update recurring_next
     $sql = "UPDATE `orders_products`\n                JOIN `products` USING(`product_id`)\n                SET `orders_products`.`recurring_next` = DATE_ADD(NOW(), INTERVAL `products`.`subscription_days` DAY)\n                WHERE FIND_IN_SET('recurring', `orders_products`.`flags`)>0\n                AND `orders_products`.`order_id`=?i";
     $msql->query($sql, $orderModel->order_id);
     if ($orderModel->billing_cycle == 0) {
         $o = clone $orderModel;
         Orders::createAttachedOrders($o);
     }
     // NEED TO UPDATE THE GATEWAY LIMITS AND STATUS.  WOULD BE BENEFICIAL IS THIS WERE SOMEHOW AN ASYNCHRONOUS FUNCTION CALL
     //if(!$this->order->isFlag('test')) {
     //$pg = new ProfileGateways('ProfileGateway');
     //$o = clone $this->order;
     //$pg->processGatewayRoutingByOrder($o);
     //unset($o);
     //}
 } else {
Example #4
0
     $paymentModel->save(false);
     continue;
 }
 $paymentModel->pn_payment_type = $pymtResp->get('PymtType');
 $paymentModel->approval_code = $pymtResp->get('ApprovalCode');
 $paymentModel->card_number = $pymtResp->get('CardNumber');
 $paymentModel->currency = $pymtResp->get('Currency');
 $paymentModel->response_cc_cvv = $pymtResp->get('CVV2ResponseCode');
 $paymentModel->filename = $pymtResp->get('Filename');
 $paymentModel->pn_status = $pymtResp->get('Status');
 $paymentModel->tracking_number = $pymtResp->get('TrackingNumber');
 $paymentModel->save(false);
 $saveOrderModel->status = 'ok';
 $saveOrderModel->payment_total = round($pymtResp->get('Amount') / 100, 2);
 $saveOrderModel->save(false);
 Event::setEvents($orderArray['order_id'], 8, false);
 if ($orderModel->billing_cycle != 0) {
     continue;
 }
 //is need insurance
 $sql = "SELECT  c.`gateway_insurance_id`,\n                        c.`product_insurance_id`\n                FROM `campaigns` as c\n                WHERE c.`campaign_id` = ?i";
 $campaign = $msql->getRow($sql, $orderModel->campaign_id);
 if (!$campaign['gateway_insurance_id'] || !$campaign['product_insurance_id']) {
     continue;
 }
 //if another insurance
 $sql = "SELECT o.*\n                FROM `orders` as o\n                WHERE o.`status` IN ('test', 'ok', 'pending', 'processing')\n                AND o.`email` = ?s\n                AND o.`gateway_id` = ?i\n                AND o.`product_id` = ?i";
 $result = $msql->getRow($sql, $orderModel->email, $campaign['gateway_insurance_id'], $campaign['product_insurance_id']);
 if ($result) {
     continue;
 }
Example #5
0
 private function finalizeOrder()
 {
     if ($this->order->billing_cycle == 0) {
         try {
             // delete prospect AND SEND IS_CUSTOMER INFO TO SILVERPOP
             Prospects::deleteProspectOkOrder($this->order->order_id);
             // send order details to the Silverpop relational table
             $this->order->addSilverpopOrderData();
         } catch (Exception $e) {
             $msg = 'PROSPECT DELETE OR SILVERPOP ERROR';
             $ord = json_encode($this->order->getDataArray());
             $pst = isset($this->post) ? json_encode($this->post) : json_encode($_POST);
             $dump = $msg . PHP_EOL . $ord . PHP_EOL . $pst . PHP_EOL;
             error_log($dump, 3, getcwd() . "/api_error_log.log");
         }
         // Fire Pixel
         $o = clone $this->order;
         Pixel::firePixelPb($o);
         unset($o);
         Event::setEvents($this->order->order_id, 8, false);
         // using try/catch here in case something happens the user will still be taken back to the thankyou page
         try {
             // is there an attach campaign associated with this order?
             // need to clone the object to be passed otherwise the createAttachedOrdersFunction will switch $this->order causing problems downstream
             $o = clone $this->order;
             Orders::createAttachedOrders($o);
             unset($o);
         } catch (Exception $e) {
             $msg = 'ATTACHED ORDER ERROR';
             $ord = json_encode($this->order->getDataArray());
             $pst = isset($this->post) ? json_encode($this->post) : json_encode($_POST);
             $dump = $msg . PHP_EOL . $ord . PHP_EOL . $pst . PHP_EOL;
             error_log($dump, 3, getcwd() . "/api_error_log.log");
         }
         if ($this->wsType == 'salvage') {
             // write log
             OrderLog::createLog(0, $this->order->order_id, 15, 'salvage order');
         }
     }
 }
Example #6
0
 function updateAction()
 {
     if (isset($_POST['ajax'])) {
         if (isset($_POST['attachOrder']) && $this->access->actionAccess('attachOrder')) {
             $orderID = AF::get($_POST, 'order_id');
             $campID = AF::get($_POST, 'camp_id', 0);
             if (!$orderID) {
                 Message::echoJsonError(__('order_attach_no_fields'));
             }
             $order = new Order();
             $order->fillFromDbPk($orderID);
             $o = clone $order;
             $r = Orders::createAttachedOrder($order, $campID, true);
             unset($order);
             unset($o);
             if ($r) {
                 Message::echoJsonSuccess(array('message' => __('order_attach_success'), 'order_id' => $r));
             } else {
                 Message::echoJsonError(__('order_attach_error'));
             }
         }
     }
     /*
     if(isset($_POST['ajax']))
     {
         if( isset($_POST['add_rocket']) && $this->access->actionAccess('rocket') )
         {
     
             $orderID = AF::get($_POST, 'order_id');
             $rocket = AF::get($_POST, 'rocket', 0);
     
             if(!$orderID)
                 Message::echoJsonError(__('order_rocket_no_fields'));
     
             $newRocket = ($rocket) ? 0 : 1;
             $orderModel = new Order();
             $orderModel->order_id = $orderID;
             $orderModel->rocket = $newRocket;
             $orderModel->setIsNewRecord(false);
     
             if($orderModel->save(false))
                 Message::echoJsonSuccess(__('order_rocket_action_'.$newRocket));
             else
                 Message::echoJsonError(__('order_rocket_not_action_'.$newRocket));
         }
     
         if(isset($_POST['update_expiry_date']) && $this->access->actionAccess('update'))
         {
             $expiryMonth = AF::get($_POST,'expiry_month');
             $expiryYear = AF::get($_POST,'expiry_year');
             $orderID = AF::get($_POST,'order_id');
     
             if(!$orderID)
                 Message::echoJsonError(__('order_incorrect_order_id'));
     
             if(!$expiryMonth || (int)$expiryMonth > 12 || !$expiryYear || (int) $expiryYear < date('Y'))
                 Message::echoJsonError(__('order_incorrect_expiry_date'));
     
             $pacnetModel = new OrderPn();
             $pacnetModel->order_id = $orderID;
             $pacnetModel->expiry_date = OrderPn::convertExpiryDateFormat($expiryMonth, $expiryYear);
             $pacnetModel->setIsNewRecord(false);
     
             if($pacnetModel->save(false))
             {
                 OrderLog::createLog($this->user->user_id, $orderID, 16, $pacnetModel->expiry_date);
                 Message::echoJsonSuccess(__('order_updeted_expiry_date'));
             }
             else
                 Message::echoJsonError(__('order_not_updeted_expiry_date'));
         }
     
         if(isset($_POST['update_cc_cvv']) && $this->access->actionAccess('update'))
         {
     
             $ccCvv = AF::get($_POST,'cc_cvv');
             $orderID = AF::get($_POST,'order_id');
     
             if(!$orderID)
                 Message::echoJsonError(__('order_incorrect_order_id'));
     
             if(!$ccCvv || strlen($ccCvv) > 4 || strlen($ccCvv) < 3)
                 Message::echoJsonError(__('order_incorrect_cc_cvv'));
     
             $pacnetModel = new OrderPn();
             $pacnetModel->fillFromDbPk($orderID);
             $arrayNote1 = unserialize(NoteBase64::decode($pacnetModel->note1));
             $arrayNote1['ccc'] = $ccCvv;
             $pacnetModel->note1 = NoteBase64::encode(serialize($arrayNote1));
             $pacnetModel->IsNewRecord = false;
             if($pacnetModel->save(false))
             {
                 OrderLog::createLog($this->user->user_id, $orderID, 17, '***');
                 Message::echoJsonSuccess(__('order_updeted_cc_cvv'));
             }
             else
                 Message::echoJsonSuccess(__('order_not_updeted_cc_cvv'));
     
     
     
         }
     }
     */
     //$model = new Order();
     $id = AF::get($this->params, 'id', FALSE);
     if (!$id) {
         throw new AFHttpException(0, 'no_id');
     }
     if (isset($_POST['set_void']) && $this->access->actionAccess('order_refund')) {
         $orderLogsModel = new OrderLog();
         $orderLogsModel->user_id = $this->user->user_id;
         $orderLogsModel->action = 3;
         if (!$orderLogsModel->canVoid()) {
             $this->redirect();
         }
         $orderModel = new Order();
         $orderModel->fillFromDbPk($id);
         if ($orderModel->status == 'void') {
             $this->redirect();
         }
         $orderModel->status = 'void';
         $orderModel->amount_refunded = '(`amount_product`+`amount_shipping`):sql';
         $orderModel->model_uset_id = $this->user->user_id;
         // remove recurring by all product
         /*
         if($orderModel->recurring == '0' || $orderModel->recurring == -1)
             $saveModel->recurring = 'NULL:sql';
         */
         if ($orderModel->save(false)) {
             //$saveModel->
             $jobModel = new Job();
             $jobModel->order_id = $orderModel->order_id;
             $jobModel->job_type = 'refund';
             $jobModel->addNew();
             //Set void events
             Event::setEvents($orderModel->order_id, 6);
             OrderLog::createLog($this->user->user_id, $id, 3);
         }
     }
     if (isset($_POST['set_shipping_address'])) {
         $orderModel = new Order();
         $orderModel->fillFromDbPk($id);
         $orderModel->address_id = $_POST['shipping_address'];
         $orderModel->save();
     }
     if (isset($_POST['set_billing_address'])) {
         $orderModel = new Order();
         $orderModel->fillFromDbPk($id);
         $orderModel->address_id = $_POST['billing_address'];
         $orderModel->save();
     }
     if (isset($_POST['cancel_retries']) && $this->access->actionAccess('update')) {
         $orderModel = Order::model()->findByPk($id);
         if ($orderModel->cancelRetries($this->user->user_id)) {
             // save success
         } else {
             // failed, now what?
         }
         $this->redirect();
     }
     if (isset($_POST['order_form_cancel_retry_set_recurring_next']) && $this->access->actionAccess('update')) {
         $productID = (int) AF::get($_POST, 'product_id');
         $recurringNext = AF::get($_POST, 'recurring_next');
         $parentOrder = Order::model()->findByPk($id);
         // have to use a different method of Order class population to not overwrite $parentOrder
         $childOrder = new Order();
         $childID = $parentOrder->hasDeclinedRebilled();
         if (!$childID) {
             return false;
         }
         $childOrder->fillFromDbPk($childID);
         if ($childOrder->cancelRetries($this->user->user_id)) {
             // set rebill date
             $orderProduct = new OrderProduct();
             $orderProduct->fillFromDbPks(array('order_id' => $id, 'product_id' => $productID));
             $orderProduct->addFlags('recurring');
             $orderProduct->recurring_next = $recurringNext;
             if ($orderProduct->save()) {
                 OrderLog::createLog($this->user->user_id, $id, 12, $recurringNext);
                 $this->redirect();
             } else {
                 return false;
             }
         } else {
             // failed, now what?
             return false;
         }
     }
     if (isset($_POST['discount_next_retries']) && $this->access->actionAccess('update')) {
         $discount = (int) AF::get($_POST, 'count_discount_next_retries');
         //$productID = (int) AF::get($_POST, 'product_id');
         if ($discount <= 0 || $discount > 100) {
             $this->redirect();
         }
         /*
         $orderModel=new Order();
         $orderModel->fillFromDbPk($id);
         */
         $orderModel = Order::model()->with('campaign')->findByPk($id);
         if ($orderModel) {
             $orderModel->amount_product = $orderModel->amount_product - $orderModel->amount_product * $discount / 100;
             $orderModel->model_uset_id = $this->user->user_id;
             if ($orderModel->save(false)) {
                 OrderLog::createLog($this->user->user_id, $id, 24, 'Discount ' . $discount . '%. New price ' . Currency::getSingPrice($orderModel->amount_product, $orderModel->campaign->currency_id));
             }
         }
         $this->redirect();
         /*
         $orderProduct=new OrderProduct();
         $orderProduct->order_id=$id;
         $orderProduct->product_id=$productID;
         //$orderProduct->fillFromDbPks(array('order_id'=>$id, 'product_id'=>$productID));
         
         $orderProduct->discount_next=$discount;
         if($orderProduct->tempUpdate())
         {
             OrderLog::createLog($this->user->user_id, $id, 24, 'Discount '.$discount.'%. New price '.$saveModel->amount_product);
         }
         */
         /*
         $orderModel = new Order();
         $orderModel->fillFromDbPk($id);
         $saveModel = new Order();
         $saveModel->order_id = $id;
         $saveModel->amount_product = $orderModel->amount_product - ($orderModel->amount_product*$discount/100);
         $saveModel->model_uset_id = $this->user->user_id;
         $saveModel->IsNewRecord = false;
         if($saveModel->save(false))
         {
             OrderLog::createLog($this->user->user_id, $id, 24, 'Discount '.$discount.'%. New price '.$saveModel->amount_product);
         }
         $this->redirect();
         */
     }
     if (isset($_POST['set_returned']) && $this->access->actionAccess('update')) {
         $reason = AF::get($_POST, 'returned_reason');
         if ($this->access->actionAccess('order_refund') && $reason) {
             $orderTempModel = new Order();
             $orderTempModel->fillFromDbPk($id);
             $saveModel = new Order();
             $saveModel->order_id = $id;
             $saveModel->returned = $reason;
             $saveModel->status = 'returned';
             $saveModel->model_uset_id = $this->user->user_id;
             $saveModel->IsNewRecord = false;
             $saveModel->save(false);
             // disable recurring to order products
             $orderProducts = OrderProducts::getProductsByOrderID($saveModel->order_id);
             foreach ($orderProducts as $orderProduct) {
                 $orderProduct->removeFlags('recurring');
                 $orderProduct->tempUpdate();
             }
             Event::setEvents($saveModel->order_id, 7);
             OrderLog::createLog($this->user->user_id, $id, 10, $reason);
         }
         $this->redirect();
     }
     if (isset($_POST['set_flags']) && $this->access->actionAccess('update')) {
         $flags = AF::get($_POST, 'flags', false);
         if (!$flags) {
             $flags = array();
         }
         $orderModel = new Order();
         $orderModel->fillFromDbPk($id);
         $orderModel->removeFlags(array('fraud', 'chargeback'));
         $orderModel->addFlags($flags);
         $orderModel->save(false);
         $customerModel = new Customer();
         $customerModel->fillFromDbPk($orderModel->customer_id);
         $customerModel->removeFlags('blacklisted');
         $customerModel->addFlags($flags);
         $customerModel->save(false);
         // Blacklisting must cancel all recurring
         if ($customerModel->isFlag('blacklisted') || $orderModel->isFlag('chargeback')) {
             Client::chargeBack($orderModel->customer_id);
         }
         OrderLog::createLog($this->user->user_id, $id, 11, implode(',', $flags));
         $this->redirect();
     }
     if (isset($_POST['set_recurring']) && $this->access->actionAccess('update')) {
         $productID = (int) AF::get($_POST, 'product_id');
         $isSet = (int) AF::get($_POST, 'is_set', 0);
         $orderProduct = OrderProduct::model()->find('order_id = :order_id AND product_id = :product_id', array(':order_id' => $id, ':product_id' => $productID));
         if ($isSet) {
             $orderProduct->addFlags('recurring');
             if (!$orderProduct->recurring_next) {
                 $updateDate = true;
             } else {
                 $date = new DateTime($orderProduct->recurring_next);
                 $updateDate = $date->getTimestamp() < time() ? true : false;
             }
             if ($updateDate) {
                 OrderProduct::updateRecurringNext($orderProduct->order_product_id);
             }
         } else {
             $orderProduct->removeFlags('recurring');
         }
         if ($orderProduct->save()) {
             OrderLog::createLog($this->user->user_id, $id, 4, $isSet ? 'yes' : 'no');
         }
         $this->redirect();
     }
     if (isset($_POST['stop_next_recurring']) && $this->access->actionAccess('update')) {
         $stopNextRecurring = AF::get($_POST, 'stop_next_recurring');
         $op_id = AF::get($_POST, 'order_product_id');
         $orderProduct = OrderProduct::model()->findByPk($op_id);
         if ($orderProduct->isFlag('recurring')) {
             if ($stopNextRecurring === '0' || $stopNextRecurring === '-1') {
                 if ($stopNextRecurring === '-1') {
                     $orderProduct->addFlags('stop_next_recurring');
                 } else {
                     $orderProduct->removeFlags('stop_next_recurring');
                 }
                 $orderProduct->save();
                 $notes = $stopNextRecurring === '0' ? 'no' : 'yes';
                 OrderLog::createLog($this->user->user_id, $id, 7, $notes);
             }
         }
         $this->redirect();
     }
     if (isset($_POST['cc_number']) && $this->access->actionAccess('update')) {
         $pacnetModel = new OrderPn();
         //$pacnetModel->fillFromDbPk($id);
         $pacnetModel->order_id = $id;
         $ccNumber = trim(AF::get($_POST, 'cc_number'));
         if ($ccNumber) {
             $pacnetModel->card_number = OrderPn::convertCreditCardNumberFormat($ccNumber);
             $arrayNote1 = unserialize(NoteBase64::decode($pacnetModel->note1));
             $arrayNote1['ccn'] = $ccNumber;
             $pacnetModel->note1 = NoteBase64::encode(serialize($arrayNote1));
             $pacnetModel->IsNewRecord = false;
             $pacnetModel->save(false);
             OrderLog::createLog($this->user->user_id, $id, 14, '**** **** **** ' . $pacnetModel->cc_number_last_four);
         }
         $this->redirect();
     }
     if (isset($_POST['set_recurring_next']) && $this->access->actionAccess('update')) {
         $productID = (int) AF::get($_POST, 'product_id');
         $recurringNext = AF::get($_POST, 'recurring_next');
         $orderProduct = new OrderProduct();
         $orderProduct->order_id = $id;
         $orderProduct->product_id = $productID;
         //$orderProduct->fillFromDbPks(array('order_id'=>$id, 'product_id'=>$productID));
         $orderProduct->recurring_next = $recurringNext;
         if ($orderProduct->tempUpdate()) {
             OrderLog::createLog($this->user->user_id, $id, 12, $recurringNext);
         }
         $this->redirect();
         /*
         $saveModel = new Order();
         $saveModel->order_id = $id;
         $saveModel->recurring_next = AF::get($_POST, 'recurring_next');
         
         if($saveModel->recurring_next)
         {
             $saveModel->model_uset_id = $this->user->user_id;
             $saveModel->IsNewRecord = false;
             $saveModel->save(false);
             OrderLog::createLog($this->user->user_id, $id, 12, $saveModel->recurring_next);
         }
         $this->redirect();
         */
     }
     $model = Order::model()->with('customer', 'campaign', 'affiliate', 'click', 'payment', 'gateway')->restrictions(array('campaign_id', 'aff_id'))->findByPk($id);
     if (!$model) {
         throw new AFHttpException(0, 'incorrect_id');
     }
     if (isset($_POST['amount_refunded']) && $this->access->actionAccess('update')) {
         $amount_refunded = AF::get($_POST, 'amount_refunded', 0);
         $model->refunded($amount_refunded);
         if (!$model->errors) {
             $jobModel = new Job();
             $jobModel->order_id = $model->order_id;
             $jobModel->job_type = 'refund';
             $jobModel->addNew();
             OrderLog::createLog($this->user->user_id, $id, 13, $amount_refunded);
         }
     }
     if (isset($_POST['set_discount_next']) && $this->access->actionAccess('update')) {
         $discount = (int) AF::get($_POST, 'discount_next');
         $productID = (int) AF::get($_POST, 'product_id');
         if ($discount <= 0 || $discount > 100) {
             $this->redirect();
         }
         $orderProduct = new OrderProduct();
         $orderProduct->order_id = $id;
         $orderProduct->product_id = $productID;
         $orderProduct->discount_next = $discount;
         if ($orderProduct->tempUpdate()) {
             OrderLog::createLog($this->user->user_id, $id, 6, $discount);
         }
         $this->redirect();
     }
     /*
     $infoPayment = array(
         'payment_type' => Payments::typeName($model->payment_type),
         'payment_method' => Payments::methodName($model->payment_type,$model->payment_method),
         //'payment_status' => $model->payment_status,
     );
     $addInfoPayment = array();
     if($model->payment_type == 'gc')
     {
         $addInfoPayment = array(
             'bank_code' => $model->bank_code,
             'issuer_id' => $model->issuer_id,
             'bank_name' => $model->bank_name,
             'bank_city' => $model->bank_city,
             'branch_code' => $model->branch_code,
             'checkdigit' => $model->checkdigit,
             'account_number' => $model->account_number,
             'account_holder' => $model->account_holder,
         );
     }
     		elseif($model->payment_type == 'pn')
     {
         $addInfoPayment = array(
             'cc_number' => '<span id="update_order_cc_number">'.$model->card_number.'</span> <a id="a_cc_update" href="javascript:AF.Orders.editCcNumber()"><i class="icon-edit"></i></a>',
             'ccv' => '<span id="update_order_cc_cvv">***</span> <a id="a_cvv_update" href="javascript:AF.Orders.editCcCvv()"><i class="icon-edit"></i></a>',
             'expiry_date' => '<span id="update_order_expiry_date">'.$model->expiry_date_formatted.'</span> <a id="a_expiry_date_update" href="javascript:AF.Orders.editExpiryDate()"><i class="icon-edit"></i></a>',
         );
     }
     $infoPayment = array_merge($infoPayment, $addInfoPayment);
     */
     /*
     $productModel = new Product();
     $productModel->fillFromDbPk($model->product_id);
     
     $recurringTotal = 0;
     
     if( $productModel->product_next_id && ($model->recurring === '0' || $model->recurring === '-1') )
     {
         $nextProductModel = new Product();
         $nextProductModel->fillFromDbPk($productModel->product_next_id);
         $shippingModel = new Shipping();
         $shippingModel->fillFromDbPk($model->shipping_id);
         $recurringTotal = ($nextProductModel->product_price + $shippingModel->amount_subscription);
         $recurringTotal =  number_format( ($recurringTotal - ($recurringTotal*$model->discount_next/100) ), 2);
     }
     
     $recurringTotal = Currency::getSingPrice($recurringTotal, $model->currency_id);
     */
     /*
     $nextProductModel = new Product();
     $nextProductModel->fillFromDbPk($productModel->product_next_id);
     */
     /*
     $msql=SafeMySQL::getInstance();
     $sql="SELECT c.*, a.*
             FROM `orders` as o
             JOIN `customers` as c USING (`customer_id`)
             JOIN `addresses` as a USING (`address_id`)
             WHERE o.`order_id`=?i";
     $allFields=$msql->getRow($sql, $model->order_id);
     fb($allFields);
     */
     $customerAddresses = Address::model()->getExistingAddresses($model->customer_id);
     $orderProducts = $model->getOrderProducts();
     $orderLogsModel = new OrderLog();
     $orderLogsModel->user_id = $this->user->user_id;
     $orderLogsModel->action = 3;
     $canVoid = $orderLogsModel->canVoid();
     $pagination = new Pagination(array('action' => $this->action, 'controller' => $this->controller, 'params' => $this->params));
     //$orderModels = AFActiveDataProvider::models('OrderLog', $this->params, $pagination);
     $orderModels = new OrderLogs('OrderLog');
     $dataProvider = $orderModels->getByOrderID($id);
     $maxAmountChargeback = 0;
     foreach ($dataProvider as $item) {
         if (in_array($item->action, array(29, 30)) && $item->amount) {
             $maxAmountChargeback += $item->amount;
         }
     }
     // we need to do some formatting here
     $paymentCRM = $model->payment->crmFormat();
     // grab attachment campaign info
     $attached = $model->getAttachedOrders();
     $model->user_id_updated = $this->user->user_id;
     $model->updated = 'NOW():sql';
     $modelAttempt = new Attempt();
     $modelAttempt->getLastOrderAttempt($model->order_id, Attempt::DEBIT_TYPE);
     //order children
     $orderChildren = Orders::getChildren($model->order_id);
     $this->addToPageTitle('Update Orders');
     Assets::js('jquery.form');
     Assets::css('jquery-ui');
     Assets::js('//code.jquery.com/ui/1.10.3/jquery-ui.js');
     Assets::js('dateRange/jquery.daterange');
     $this->render('update', array('model' => $model, 'paymentModel' => $paymentCRM, 'orderProducts' => $orderProducts, 'canVoid' => $canVoid, 'dataProvider' => $dataProvider, 'customerAddresses' => $customerAddresses, 'attached' => $attached, 'maxAmountChargeback' => $maxAmountChargeback, 'modelAttempt' => $modelAttempt, 'orderChildren' => $orderChildren));
 }