public function add($autodate = true, $null_values = false) { if (!parent::add($autodate)) { return false; } $order = new Order((int) $this->id_order); // Update id_order_state attribute in Order $order->current_state = $this->id_order_state; $order->update(); // start of implementation of the module code - taxamo $operation = null; $list_orderstateoperation = Taxamoeuvat::getListValues(); foreach ($list_orderstateoperation as $orderstateoperation) { if ($orderstateoperation['id_order_state'] == $order->current_state) { $operation = $orderstateoperation['operation']; } } if (!is_null($operation)) { if ($operation == 1 || $operation == 2) { $last_id_order_transaction = Taxamoeuvat::getLastIdByOrder($order->id); if (is_null($last_id_order_transaction)) { $res_process_store_transaction = Tools::taxamoStoreTransaction($order->id_currency, $order->id_address_invoice, $order->id_customer, $order->getCartProducts()); if (is_null($res_process_store_transaction['key_transaction'])) { $res_process_store_transaction['comment'] .= '* Transaccion NO Adicionada'; } else { $res_process_store_transaction['comment'] .= '* Transaccion ADICIONADA'; } Taxamoeuvat::addTransaction($order->id, $order->current_state, $res_process_store_transaction['key_transaction'], $res_process_store_transaction['comment']); } else { $reg_taxamo_transaction = null; $reg_taxamo_transaction = Taxamoeuvat::idExistsTransaction((int) $last_id_order_transaction); $res_process_store_transaction['key_transaction'] = $reg_taxamo_transaction[0]['key_transaction']; $res_process_store_transaction['comment'] = ''; } if ($operation == 2) { if (is_null($res_process_store_transaction['key_transaction'])) { $res_process_store_transaction['comment'] .= '* Transaccion NO Confirmada'; } else { $res_process_confirm_transaction = Tools::taxamoConfirmTransaction($res_process_store_transaction['key_transaction']); if (!is_null($res_process_confirm_transaction['status']) && $res_process_confirm_transaction['status'] == 'C') { $res_process_store_transaction['comment'] .= '* Transaccion CONFIRMADA'; } else { if (!empty($res_process_confirm_transaction['error'])) { $res_process_store_transaction['comment'] .= $res_process_confirm_transaction['error']; $res_process_store_transaction['comment'] .= '* Transaccion NO Confirmada'; } } } Taxamoeuvat::addTransaction($order->id, $order->current_state, $res_process_store_transaction['key_transaction'], $res_process_store_transaction['comment']); } } } // end of code implementation module - taxamo Hook::exec('actionOrderHistoryAddAfter', array('order_history' => $this), null, false, true, false, $order->id_shop); return true; }
public function addPartialSlipDetail($order_detail_list) { // start of implementation of the module code - taxamo $reg_taxamo_transaction = null; $last_id_order_transaction = Taxamoeuvat::getLastIdByOrder($this->id_order); if (!is_null($last_id_order_transaction)) { $reg_taxamo_transaction = Taxamoeuvat::idExistsTransaction((int) $last_id_order_transaction); } // end of code implementation module - taxamo foreach ($order_detail_list as $id_order_detail => $tab) { $order_detail = new OrderDetail($id_order_detail); $order_slip_resume = self::getProductSlipResume($id_order_detail); if ($tab['amount'] + $order_slip_resume['amount_tax_incl'] > $order_detail->total_price_tax_incl) { $tab['amount'] = $order_detail->total_price_tax_incl - $order_slip_resume['amount_tax_incl']; } if ($tab['amount'] == 0) { continue; } if ($tab['quantity'] + $order_slip_resume['product_quantity'] > $order_detail->product_quantity) { $tab['quantity'] = $order_detail->product_quantity - $order_slip_resume['product_quantity']; } $tab['amount_tax_excl'] = $tab['amount_tax_incl'] = $tab['amount']; $id_tax = (int) Db::getInstance()->getValue('SELECT `id_tax` FROM `' . _DB_PREFIX_ . 'order_detail_tax` WHERE `id_order_detail` = ' . (int) $id_order_detail); if ($id_tax > 0) { $rate = (double) Db::getInstance()->getValue('SELECT `rate` FROM `' . _DB_PREFIX_ . 'tax` WHERE `id_tax` = ' . (int) $id_tax); if ($rate > 0) { $rate = 1 + $rate / 100; $tab['amount_tax_excl'] = $tab['amount_tax_excl'] / $rate; } } if ($tab['quantity'] > 0 && $tab['quantity'] > $order_detail->product_quantity_refunded) { $order_detail->product_quantity_refunded = $tab['quantity']; $order_detail->save(); } $insert_order_slip = array('id_order_slip' => (int) $this->id, 'id_order_detail' => (int) $id_order_detail, 'product_quantity' => (int) $tab['quantity'], 'amount_tax_excl' => (double) $tab['amount_tax_excl'], 'amount_tax_incl' => (double) $tab['amount_tax_incl']); Db::getInstance()->insert('order_slip_detail', $insert_order_slip); // start of implementation of the module code - taxamo if (!is_null($reg_taxamo_transaction)) { Tools::taxamoRefunds($reg_taxamo_transaction[0]['key_transaction'], $order_detail->product_id, (double) $tab['amount_tax_incl']); } // end of code implementation module - taxamo } }