function delete_tax($id) { log_debug("taxes", "Executing delete_tax_details({$id}, values...)"); if (user_permissions_get("accounts_taxes_write")) { $obj_tax = new tax(); /* Load SOAP Data */ $obj_tax->id = @security_script_input_predefined("int", $id); if (!$obj_tax->id || $obj_tax->id == "error") { throw new SoapFault("Sender", "INVALID_INPUT"); } /* Error Handling */ // verify tax ID if (!$obj_tax->verify_id()) { throw new SoapFault("Sender", "INVALID_ID"); } // check that the tax can be safely deleted if ($obj_tax->check_delete_lock()) { throw new SoapFault("Sender", "LOCKED"); } /* Perform Changes */ if ($obj_tax->action_delete()) { return 1; } else { throw new SoapFault("Sender", "UNEXPECTED_ACTION_ERROR"); } } else { throw new SoapFault("Sender", "ACCESS DENIED"); } }
<?php require_once 'tax.php'; require_once 'link.php'; $stationFromID = 60003760; $stationToID = 60008494; $link = new link(); $con = $link->connect(); $character_get = 95060857; $transFrom = "buy"; $transTo = "sell"; $taxcalc = new tax($stationFromID, $stationToID, $con, $character_get, $transFrom, $transTo); /* echo ($taxcalc->getCorpOwnerIDFromStation()); echo ($taxcalc->getCorpOwnerIDToStation()); echo ($taxcalc->getFactionOwnerIDFromStation($taxcalc->getCorpOwnerIDFromStation())); echo ($taxcalc->getFactionOwnerIDToStation($taxcalc->getCorpOwnerIDToStation())); echo $taxcalc->getFromCorpStanding($taxcalc->getCorpOwnerIDFromStation()); echo $taxcalc->getToCorpStanding($taxcalc->getCorpOwnerIDToStation()); echo ($taxcalc->getFromFactionStanding($taxcalc->getFactionOwnerIDFromStation($taxcalc->getCorpOwnerIDFromStation()))); echo ($taxcalc->getToFactionStanding($taxcalc->getFactionOwnerIDToStation($taxcalc->getCorpOwnerIDToStation()))); echo $taxcalc->getBrokerLevel(); echo $taxcalc->getAccountingLevel();*/ echo $taxcalc->calculateBrokerFrom();
function sweep($type) { $this->charge_construct(); include_once PATH_MODULES . 'account_billing/account_billing.inc.php'; $account_billing = new account_billing(); include_once PATH_MODULES . 'tax/tax.inc.php'; $taxObj = new tax(); include_once PATH_MODULES . 'discount/discount.inc.php'; $db =& DB(); $sql = "SELECT DISTINCT\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.id,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.account_id,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.service_id,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.amount,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.taxable,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.attributes,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.quantity,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.product_id,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.description, \n\t\t\t\t\t" . AGILE_DB_PREFIX . "account.affiliate_id,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "account.reseller_id,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "account.country_id,\n\t\t\t\t\t" . AGILE_DB_PREFIX . "account.currency_id, \n\t\t\t\t\t" . AGILE_DB_PREFIX . "account.state \n\t\t\t\tFROM \n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge \t\t\n\t\t\t\tLEFT JOIN \n\t\t\t\t\t" . AGILE_DB_PREFIX . "account \t\t\t\n\t\t\t\tON \n\t\t\t\t\t" . AGILE_DB_PREFIX . "account.id \t\t = " . AGILE_DB_PREFIX . "charge.account_id \t\t\t\t\t\t\t\n\t\t\t\tWHERE \n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.site_id \t = " . $db->qstr(DEFAULT_SITE) . " \n\t\t\t\tAND \n\t\t\t\t\t" . AGILE_DB_PREFIX . "account.site_id \t = " . $db->qstr(DEFAULT_SITE) . "\t\t\t\n\t\t\t\tAND\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.status \t = " . $db->qstr('0') . " \n\t\t\t\tAND\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.sweep_type = " . $db->qstr($type) . "\n\t\t\t\tORDER BY\n\t\t\t\t\t" . AGILE_DB_PREFIX . "charge.account_id"; $rs = $db->Execute($sql); if ($rs === false) { global $C_debug; $C_debug->error('charge.inc.php', 'charge :: sweep()', $db->ErrorMsg() . "\r\n\r\n" . $sql); return false; } $account_id = false; $invoice_id = false; $i = false; $i_total = false; $invoice_count = 0; $sweep_count = 0; while (!$rs->EOF) { if ($rs->fields['account_id'] != $account_id) { $account_id = $rs->fields['account_id']; $i = 0; $i_total = $this->count_account_charges($account_id, $rs->CurrentRow(), $rs); $sub_total = 0; $taxable_amount = 0; $this_discount_total = 0; $tax_amt = 0; $discount_amt = 0; # Start a new transaction $trans =& DB(); $trans->StartTrans(); # Start a new invoice $invoice_id = $db->GenID(AGILE_DB_PREFIX . 'invoice_id'); # check for any discounts for the parent invoice or account_id (applied at checkout and should continue to be applied if recurring type discount) $discountObj = new discount(); # get parent invoice id if service specified (for discount checking) $parent_invoice_id = false; if ($rs->fields['service_id']) { $parentinv = $db->Execute(sqlSelect($db, "service", "invoice_id", "id={$rs->fields['service_id']}")); if ($parentinv && $parentinv->RecordCount()) { $parent_invoice_id = $parentinv->fields['invoice_id']; } } # get available discounts to this account/service $discountObj->available_discounts($account_id, 1, $parent_invoice_id); } ########################### ##### LINE ITEM ACTIONS ### ########################### if (!empty($account_id)) { ### Get the line item id $invoice_item_id = $db->GenID(AGILE_DB_PREFIX . 'invoice_item_id'); ### Set the invoice item details: $product_id = $rs->fields['product_id']; if (!empty($product_id) && empty($this->product["{$product_id}"])) { $sql = "SELECT sku FROM " . AGILE_DB_PREFIX . "product WHERE \n\t\t\t\t\t\t\tid \t= " . $db->qstr($product_id) . " AND\n\t\t\t\t\t\t\tsite_id = " . $db->qstr(DEFAULT_SITE); $prod = $db->Execute($sql); if ($prod->RecordCount() > 0) { $sku = $prod->fields['sku']; $this->product["{$product_id}"] = $sku; $product_attr = ''; if (!empty($rs->fields['description'])) { $product_attr = "Description=={$rs->fields['description']}\r\n"; } $product_attr .= $rs->fields['attributes']; } else { $sku = $rs->fields['description']; $this->product["{$product_id}"] = $sku; $product_attr = $rs->fields['attributes']; } } elseif (!empty($this->product["{$product_id}"])) { $sku = $this->product["{$product_id}"]; $product_attr = $rs->fields['attributes']; } else { $sku = $rs->fields['description']; $product_attr = $rs->fields['attributes']; } $quantity = $rs->fields['quantity']; $price_base = $rs->fields['amount']; $item_total_amt = $price_base * $quantity; // Calculate any recurring discounts for this account $item_discount_amt = $discountObj->calc_all_discounts(1, $invoice_item_id, $rs->fields['product_id'], $item_total_amt, $account_id, $sub_total + $item_total_amt); $item_total_amt -= $item_discount_amt; $sub_total += $item_total_amt; $discount_amt += $item_discount_amt; # calculate any taxes for this item $item_tax_amt = 0; if ($rs->fields['taxable']) { $item_tax_arr = $taxObj->calculate($item_total_amt, $rs->fields['country_id'], $rs->fields['state']); if (is_array($item_tax_arr)) { foreach ($item_tax_arr as $tx) { $item_tax_amt += $tx['rate']; } } $tax_amt += $item_tax_amt; } ### Add line item to new invoice $sql = "INSERT INTO " . AGILE_DB_PREFIX . "invoice_item SET\n\t\t\t\t\t\tid\t\t\t\t\t = " . $db->qstr($invoice_item_id) . ",\n\t\t\t\t\t\tsite_id\t\t\t\t = " . $db->qstr(DEFAULT_SITE) . ",\n\t\t\t\t\t\tinvoice_id\t\t\t = " . $db->qstr($invoice_id) . ",\n\t\t\t\t\t\taccount_id\t\t\t\t= " . $db->qstr($account_id) . ",\n\t\t\t\t\t\tdate_orig\t\t\t = " . $db->qstr(time()) . ",\n\t\t\t\t\t\tproduct_id\t\t\t = " . $db->qstr($product_id) . ",\n\t\t\t\t\t\tsku\t\t\t\t\t = " . $db->qstr($sku) . ",\n\t\t\t\t\t\tquantity\t\t\t = " . $db->qstr($quantity) . ",\n\t\t\t\t\t\titem_type\t\t\t = " . $db->qstr('0') . ",\n\t\t\t\t\t\tproduct_attr\t\t = " . $db->qstr($product_attr) . ", \n\t\t\t\t\t\tprice_type = " . $db->qstr('0') . ",\n\t\t\t\t\t\tprice_base\t\t\t = " . $db->qstr($price_base) . ",\n\t\t\t\t\t\tprice_setup\t\t\t = " . $db->qstr(0) . ",\n\t\t\t\t\t\ttax_amt\t\t\t\t\t= " . $db->qstr($item_tax_amt) . ",\n\t\t\t\t\t\ttotal_amt\t\t\t\t= " . $db->qstr($item_total_amt) . ",\n\t\t\t\t\t\tdiscount_amt\t\t\t= " . $db->qstr($item_discount_amt); $trans->Execute($sql); # Insert tax records $taxObj->invoice_item($invoice_id, $invoice_item_id, $account_id, @$item_tax_arr); # Insert discount records $discountObj->invoice_item($invoice_id, $invoice_item_id, $account_id); ### Update this charge status to billed $sql = "UPDATE " . AGILE_DB_PREFIX . "charge SET\n\t\t\t\t\t\tstatus \t= " . $db->qstr('1') . " \n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\tsite_id\t = " . $db->qstr(DEFAULT_SITE) . " AND \n\t\t\t\t\t\tid\t\t = " . $db->qstr($rs->fields['id']); $trans->Execute($sql); $i++; $sweep_count++; } ####################### ### INVOICE ACTIONS ### ####################### if ($i_total == $i || $i == $rs->RecordCount()) { if ($invoice_id) { ### Get the most recent billing id for this client: if (!isset($billing_id["{$account_id}"])) { $billing_arr = $account_billing->default_billing($account_id); $billing_id["{$account_id}"] = $billing_arr['billing_id']; $checkout_plugin_id["{$account_id}"] = $billing_arr['checkout_plugin_id']; } ### Affiliate & Reseller info: $affiliate_id = $rs->fields['affiliate_id']; $reseller_id = $rs->fields['reseller_id']; $actual_billed_currency_id = $rs->fields['currency_id']; # calculate any taxes @($total = $sub_total + $tax_amt); if ($total <= 0) { $process_status = 1; $billing_status = 1; } else { $process_status = 0; $billing_status = 0; } ### Generate the invoice insert SQL: $sql = "INSERT INTO " . AGILE_DB_PREFIX . "invoice SET\n\t\t\t\t\t\t\t\tid\t\t\t\t\t\t\t= " . $db->qstr($invoice_id) . ",\n\t\t\t\t\t\t\t\tsite_id\t\t\t\t\t\t= " . $db->qstr(DEFAULT_SITE) . ",\n\t\t\t\t\t\t\t\tdate_orig\t\t\t\t\t= " . $db->qstr(time()) . ",\n\t\t\t\t\t\t\t\tdate_last\t\t\t\t\t= " . $db->qstr(time()) . ",\n\t\t\t\t\t\t\t\tprocess_status\t\t\t\t= " . $db->qstr($process_status) . ",\n\t\t\t\t\t\t\t\tbilling_status\t\t\t\t= " . $db->qstr($billing_status) . ",\n\t\t\t\t\t\t\t\tprint_status\t\t\t\t= " . $db->qstr('0') . ",\n\t\t\t\t\t\t\t\taccount_id\t\t\t\t\t= " . $db->qstr($account_id) . ",\n\t\t\t\t\t\t\t\taccount_billing_id\t\t\t= " . $db->qstr($billing_id["{$account_id}"]) . ",\n\t\t\t\t\t\t\t\taffiliate_id\t\t\t\t= " . $db->qstr($affiliate_id) . ",\n\t\t\t\t\t\t\t\treseller_id\t\t\t\t\t= " . $db->qstr($reseller_id) . ",\n\t\t\t\t\t\t\t\tcheckout_plugin_id\t\t\t= " . $db->qstr($checkout_plugin_id["{$account_id}"]) . ", \n\t\t\t\t\t\t\t\ttax_amt\t\t\t\t\t\t= " . $db->qstr($tax_amt) . ", \n\t\t\t\t\t\t\t\tdiscount_amt\t\t\t\t= " . $db->qstr($discount_amt) . ",\n\t\t\t\t\t\t\t\tactual_billed_currency_id\t= " . $db->qstr($actual_billed_currency_id) . ",\n\t\t\t\t\t\t\t\tactual_billed_amt\t\t\t= " . $db->qstr('0') . ",\n\t\t\t\t\t\t\t\tbilled_currency_id\t\t\t= " . $db->qstr(DEFAULT_CURRENCY) . ",\n\t\t\t\t\t\t\t\tbilled_amt\t\t\t\t\t= " . $db->qstr('0') . ",\n\t\t\t\t\t\t\t\ttotal_amt\t\t\t\t\t= " . $db->qstr($total) . ",\n\t\t\t\t\t\t\t\tnotice_count\t\t\t\t= " . $db->qstr('0') . ",\n\t\t\t\t\t\t\t\tnotice_max\t\t\t\t\t= " . $db->qstr(MAX_BILLING_NOTICE) . ",\n\t\t\t\t\t\t\t\tnotice_next_date\t\t\t= " . $db->qstr(time()) . ",\n\t\t\t\t\t\t\t\tgrace_period\t\t\t\t= " . $db->qstr(GRACE_PERIOD) . ",\n\t\t\t\t\t\t\t\tdue_date\t\t\t\t\t= " . $db->qstr(time()); $trans->Execute($sql); ### Close this transaction $trans->CompleteTrans(); $i_total = false; $i = false; $account_id = false; $invoice_id = false; $discount = false; $cookie = false; $invoice_count++; } } $rs->MoveNext(); } global $C_debug; $C_debug->alert("Swept {$sweep_count} Charge(s) into {$invoice_count} Invoice(s)."); return true; }
function update($VAR) { global $C_list, $C_debug; if (!$this->checkLimits()) { return false; } // check account limits // validate the tax_id global $VAR; require_once PATH_MODULES . 'tax/tax.inc.php'; $taxObj = new tax(); $tax_arr = @$VAR['account_admin_tax_id']; if (is_array($tax_arr)) { foreach ($tax_arr as $country_id => $tax_id) { if ($country_id == $VAR['account_admin_country_id']) { $exempt = @$VAR["account_tax_id_exempt"][$country_id]; if (!($txRs = $taxObj->TaxIdsValidate($country_id, $tax_id, $exempt))) { $this->validated = false; global $C_translate; $this->val_error[] = array('field' => 'account_admin_tax_id', 'field_trans' => $taxObj->errField, 'error' => $C_translate->translate('validate_general', "", "")); } if ($exempt) { $VAR['account_admin_tax_id'] = false; } else { $VAR['account_admin_tax_id'] = $tax_id; } } } } #################################################################### ### Get required static_Vars and validate them... return an array ### w/ ALL errors... #################################################################### require_once PATH_CORE . 'static_var.inc.php'; $static_var = new CORE_static_var(); if (!isset($this->val_error)) { $this->val_error = false; } $all_error = $static_var->validate_form('account', $this->val_error); if ($all_error != false && gettype($all_error) == 'array') { $this->validated = false; } else { $this->validated = true; } #################################################################### # If validation was failed, skip the db insert & # set the errors & origonal fields as Smarty objects, # and change the page to be loaded. #################################################################### if (!$this->validated) { global $smarty; # set the errors as a Smarty Object $smarty->assign('form_validation', $all_error); # set the page to be loaded if (!defined("FORCE_PAGE")) { define('FORCE_PAGE', $VAR['_page_current']); } return; } ### Get the old username ( for db mapping ) $db =& DB(); $sql = 'SELECT username FROM ' . AGILE_DB_PREFIX . 'account WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND id = ' . $db->qstr($VAR['account_admin_id']); $result = $db->Execute($sql); if ($result->RecordCount() > 0) { $old_username = $result->fields['username']; } ### Update the password: $update_password = false; if (!empty($VAR['_password'])) { $VAR['account_admin_password'] = $VAR['_password']; /* check if new password is ok */ if ($C_list->is_installed('account_password_history')) { include_once PATH_MODULES . 'account_password_history/account_password_history.inc.php'; $accountHistory = new account_password_history(); if (!$accountHistory->getIsPasswordOk($VAR['account_admin_id'], $VAR['account_admin_password'], false)) { $C_debug->alert("The password you have selected has been used recently and cannot be used again at this time for security purposes."); unset($VAR['account_admin_password']); } else { $update_password = true; } } } ### Update the record $type = "update"; $this->method["{$type}"] = explode(",", $this->method["{$type}"]); $db = new CORE_database(); $ok = $db->update($VAR, $this, $type); if ($ok) { /* password logging class */ if ($update_password && is_object($accountHistory)) { $accountHistory->setNewPassword($VAR['account_admin_id'], $VAR["account_admin_password"], false); } ### Update the static vars: $static_var->update($VAR, 'account', $VAR['account_admin_id']); ### Do any db_mapping if ($C_list->is_installed('db_mapping')) { include_once PATH_MODULES . 'db_mapping/db_mapping.inc.php'; $db_map = new db_mapping(); if (!empty($VAR['account_admin_password'])) { $db_map->plaintext_password = $VAR['account_admin_password']; } else { $db_map->plaintext_password = false; } $db_map->account_edit($VAR['account_admin_id'], $old_username); } // remove login lock if ($VAR['account_admin_status']) { $db =& DB(); $delrs = $db->Execute($sql = sqlDelete($db, "login_lock", "account_id={$VAR['account_admin_id']}")); $delrs = $db->Execute($sql = sqlDelete($db, "login_log", "account_id={$VAR['account_admin_id']} AND status=0")); } return true; } }
//} $PAGE->set_url('/local/onlinepayment/paymentstatus.php'); $PAGE->set_title(get_string('paymentdetails', 'local_onlinepayment')); //Header and the navigation bar $PAGE->set_heading(get_string('paymentdetails', 'local_onlinepayment')); $PAGE->requires->css('/local/onlinepayment/css/style.css'); //$PAGE->navbar->add(get_string('pluginname', 'local_onlinepayment'), new moodle_url('/local/onlinepayment/index.php')); $PAGE->navbar->add(get_string('paymentdetails', 'local_onlinepayment')); echo $OUTPUT->header(); //Heading of the page //echo $OUTPUT->heading(get_string('paymentdetails', 'local_onlinepayment')); $trans = onlinepay_transaction::getInstance(); $tax = tax::getInstance(); $schoollist = $hierarchy->get_assignedschools(); if (is_siteadmin()) { $schoollist = $hierarchy->get_school_items(); } $schoollist = $hierarchy->get_school_parent($schoollist, $selected = array(), $inctop = false, $all = false); //$filter = new status_filter_form(); //$filter->display(); //$records = $tax->get_payment_status($schoollist, $fullname); //print_object($records); $data = array(); if ($orderid) { echo $OUTPUT->heading(get_string('paymentdetails', 'local_onlinepayment')); $record = $tax->get_payment_status($schoollist, $orderid); $semester = $DB->get_record('local_semester', array('id' => $record->semesterid));
function regionalTrader($con, $character_get) { $dt = new DateTime(); $tz = new DateTimeZone('Europe/Lisbon'); $dt->setTimezone($tz); $datetime = $dt->format('Y-m-d H:i:s'); if (isset($_POST['Submit3'])) { //User added another item to the table $newItemName = mysqli_real_escape_string($con, $_POST['tag4']); $itemID = utils::mysqli_result(mysqli_query($con, "SELECT eve_iditem FROM item WHERE name= '{$newItemName}'"), 0, 0); $transFrom = mysqli_real_escape_string($con, $_GET['tr1']); $transTo = mysqli_real_escape_string($con, $_GET['tr2']); $stationFromID = mysqli_real_escape_string($con, $_GET['sys1']); $stationToID = mysqli_real_escape_string($con, $_GET['sys2']); $systemFromName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM system WHERE eve_idsystem = " . "(SELECT system_eve_idsystem FROM station WHERE eve_idstation = '{$stationFromID}')"), 0, 0) or mysqli_error($con); $systemToName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM system WHERE eve_idsystem = " . "(SELECT system_eve_idsystem FROM station WHERE eve_idstation = '{$stationToID}')"), 0, 0) or mysqli_error($con); $systemFromID = utils::mysqli_result(mysqli_query($con, "SELECT system_eve_idsystem FROM station WHERE eve_idstation = '{$stationFromID}'"), 0, 0) or mysqli_error($con); $systemToID = utils::mysqli_result(mysqli_query($con, "SELECT system_eve_idsystem FROM station WHERE eve_idstation = '{$stationToID}'"), 0, 0) or mysqli_error($con); $stationFromName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM station WHERE eve_idstation = '{$stationFromID}'"), 0, 0) or die(mysqli_error($con)); $stationToName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM station WHERE eve_idstation = '{$stationToID}'"), 0, 0) or die(mysqli_error($con)); if ($stationFromID == "" | $stationToID == "") { echo "Invalid solar system provided."; echo "<a href='regionaltrade.php?character={$character_get}'>Regional Trader Assistant </a>"; die; } if ($itemID == "") { echo "Invalid item provided"; //send hidden GET with solarsys+trans echo " <form name='regional_3' action = 'regionaltrade.php?character={$character_get}&sys1={$systemFromID}&sys2={$systemToID}&tr1={$transFrom}&tr2={$transTo}' method='POST'>"; //form that sends the user back to submit=3 so we don't lose previously submitted items die; } //calculate tax - all tax variables come from here $taxcalc = new tax($stationFromID, $stationToID, $con, $character_get, $transFrom, $transTo); $transTaxFrom = $taxcalc->calculateTaxFrom(); $transTaxTo = $taxcalc->calculateTaxTo(); $brokerFeeFrom = $taxcalc->calculateBrokerFrom(); $brokerFeeTo = $taxcalc->calculateBrokerTo(); //taxcalc($stationFromID,$stationFromID,$character_get,$con,$transFrom,$transTo); //draw table echo "<h4>" . $stationFromName . "(" . $transFrom . ")" . " <i class='fa fa-arrow-circle-o-right fa-fw'></i> " . $stationToName . "(" . $transTo . ")" . "</h4><br>"; //Tax info echo "<i class='fa fa-chevron-circle-right fa-fw'></i>" . "<b>Broker(origin):</b>" . max(0, number_format(($brokerFeeFrom - 1) * 100, 2)) . "%" . " " . "<i class='fa fa-chevron-circle-right fa-fw'></i>" . "<b>Tax (origin):</b>" . number_format(($transTaxFrom - 1) * 100, 2) . "%" . " " . "<i class='fa fa-chevron-circle-right fa-fw'></i>" . "<b>Broker(dest.):</b>" . max(0, number_format(($brokerFeeTo - 1) * 100, 2)) . "%" . " " . "<i class='fa fa-chevron-circle-right fa-fw'></i>" . "<b>Tax (dest.):</b>" . abs(number_format(($transTaxTo - 1) * 100, 2)) . "%" . " " . "<br><br>"; echo "<table class='table table-striped table-bordered table-hover' id='dataTables-example'>"; echo "<thead><tr>" . "<th>" . "Item" . "</th>" . "<th>" . $systemFromName . " " . $transFrom . " price" . "</th>" . "<th align = 'right'>" . "Broker fee" . "</th>" . "<th>" . $systemToName . " " . $transTo . " price" . "</th>" . "<th align = 'right'>" . "Broker fee" . "</th>" . "<th align = 'right'>" . "Transaction Tax" . "</th>" . "<th align = 'right'>" . "Raw profit" . "</th>" . "<th align = 'right'>" . "Margin (%)" . "</th></tr></thead>"; //To avoid re-calculating all previous entries, we create a temp cache that stores all previous values submitted in this session. $get_cache_results = mysqli_query($con, "SELECT DISTINCT * FROM cache_tool WHERE character_eve_idcharacter = '{$character_get}' ORDER BY timestamp ASC") or die(mysqli_error($con)); //check if item is already submitted $priceFrom = getEveCentralData($itemID, $systemFromID, $transFrom); // * $brokerFeeFrom * $transTaxFrom; $priceTo = getEveCentralData($itemID, $systemToID, $transTo); // * $brokerFeeTo * $transTaxTo; $profitRaw = $priceTo * $brokerFeeTo * $transTaxTo - $priceFrom * $brokerFeeFrom; $brokerFeeFromVal = max(100, $priceFrom * ($brokerFeeFrom - 1)); $brokerFeeToVal = max(100, $priceTo * (1 - $brokerFeeTo)); $transTaxToVal = $priceFrom * (1 - $transTaxTo); if ($priceFrom > 0 && $priceTo > 0) { $profitMargin = $profitRaw / $priceFrom * 100; } else { $profitMargin = "Error"; } //add results to table from cache, then add the last submitted item at the end while ($row2 = mysqli_fetch_array($get_cache_results)) { $cachedItemID = $row2['item_eveiditem']; $cachedPriceFrom = $row2['priceFrom']; //add exceptions for when buy or sell = 0 $cachedPriceTo = $row2['priceTo']; $cachedProfit = $row2['profit']; $cachedMargin = $row2['margin']; $cachedItemName = $row2['item_name']; $cachedBrokerFrom = $row2['brokerFrom']; $cachedBrokerTo = $row2['brokerTo']; $cachedTransTo = $row2['transTo']; $cachedProfit > 0 ? $color = "class='success'" : ($color = "class='danger'"); echo "<tr {$color}>" . "<td>" . "<img src='../Types/" . $cachedItemID . "_32.png'>" . " " . $cachedItemName . "</td>" . "<td align = 'right'>" . number_format((double) $cachedPriceFrom) . "</td>" . "<td align = 'right'>" . number_format((double) $cachedBrokerFrom) . "</td>" . "<td align = 'right'>" . number_format((double) $cachedPriceTo) . "</td>" . "<td align = 'right'>" . number_format((double) $cachedBrokerTo) . "</td>" . "<td align = 'right'>" . number_format((double) $cachedTransTo) . "</td>" . "<td align = 'right'>" . number_format((double) $cachedProfit) . "</td>" . "<td align = 'right'>" . utils::formating_profit(round($cachedMargin, 2)) . "</td></tr>"; // print_r($row2); var_dump($row2); } $check_duplicate_item = mysqli_query($con, "SELECT * FROM cache_tool WHERE item_eveiditem = '{$itemID}' AND character_eve_idcharacter = '{$character_get}'") or die(mysqli_error($con)); if (mysqli_num_rows($check_duplicate_item) > 0) { echo "<i class='fa fa-exclamation fa-fw'></i><b>Item already exists in this list</b><br>"; ?> </tbody></table> <link rel="stylesheet" type="text/css" href="scripts/jquery.autocomplete.css" /> <script type="text/javascript" src="scripts/jquery.js"></script> <script type="text/javascript" src="scripts/jquery.autocomplete.js"></script> <script>var jQueryAutocomplete = $.noConflict(true);</script> <script> $(document).ready(function(){ jQueryAutocomplete("#tag4").autocomplete("scripts/autocomplete_i.php", { selectFirst: true }); }); </script> </head> <body> <?php echo " <form name='regional_3' action = 'regionaltrade.php?character={$character_get}&sys1={$stationFromID}&sys2={$stationToID}&tr1={$transFrom}&tr2={$transTo}' method='POST'>"; //send both post and get at same time ?> <label>Add Item: </label> <input name="tag4" type="text" id="tag4" size="50"/> <input type="Submit" value="Submit" name="Submit3" class="btn btn-success"" /> </form> <?php } else { $profitRaw > 0 ? $color = "class='success'" : ($color = "class='danger'"); echo "<tr {$color}>" . "<td>" . "<img src='../Types/" . $itemID . "_32.png'>" . " " . $newItemName . "</td>" . "<td align = 'right'>" . number_format($priceFrom) . "</td>" . "<td align = 'right'>" . number_format($brokerFeeFromVal) . "</td>" . "<td align = 'right'>" . number_format($priceTo) . "</td>" . "<td align = 'right'>" . number_format($brokerFeeToVal) . "</td>" . "<td align = 'right'>" . number_format($transTaxToVal) . "</td>" . "<td align = 'right'>" . number_format($profitRaw) . "</td>" . "<td align = 'right'>" . utils::formating_profit(round($profitMargin, 2)) . "</td></tr>"; mysqli_query($con, "INSERT INTO `trader`.`cache_tool` (`idcache_tool`, `priceFrom`, `priceTo`, `profit`, `margin`, `timestamp`, `item_eveiditem`, `character_eve_idcharacter`, `item_name`, `brokerFrom`, `brokerTo`, `transTo`) \n VALUES (NULL, '{$priceFrom}', '{$priceTo}', '{$profitRaw}', '{$profitMargin}', '{$datetime}', '{$itemID}', '{$character_get}', '{$newItemName}', '{$brokerFeeFromVal}', '{$brokerFeeToVal}', '{$transTaxToVal}')") or die(mysqli_error($con)); echo "</table>"; ?> <link rel="stylesheet" type="text/css" href="scripts/jquery.autocomplete.css" /> <script type="text/javascript" src="scripts/jquery.js"></script> <script type="text/javascript" src="scripts/jquery.autocomplete.js"></script> <script type="text/javascript">var jQueryAutocomplete = $.noConflict(true);</script> <script> $(document).ready(function(){ jQueryAutocomplete("#tag4").autocomplete("scripts/autocomplete_i.php", { selectFirst: true }); }); </script> </head> <body> <?php echo " <form name='regional_3' action = 'regionaltrade.php?character={$character_get}&sys1={$stationFromID}&sys2={$stationToID}&tr1={$transFrom}&tr2={$transTo}' method='POST'>"; //send both post and get at same time ?> <label>Add Item: </label> <input name="tag4" type="text" id="tag4" size="50"/> <input type="Submit" value="Submit" name="Submit3" class="btn btn-success" /> </form> <?php } } else { if (isset($_POST['Submit2'])) { //User submits an item to the list //Update data list $itemName = mysqli_real_escape_string($con, $_POST['tag3']); //echo $itemName; $itemID = utils::mysqli_result(mysqli_query($con, "SELECT eve_iditem FROM item WHERE name= '{$itemName}'"), 0, 0); $stationFromID = mysqli_real_escape_string($con, $_GET['sys1']); $stationToID = mysqli_real_escape_string($con, $_GET['sys2']); if ($stationFromID == "" | $stationToID == "") { echo "Invalid solar system provided."; echo "<a href='regionaltrade.php?character={$character_get}'>Regional Trader Assistant </a>"; die; } $systemFromName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM system WHERE eve_idsystem = (SELECT system_eve_idsystem FROM station WHERE eve_idstation = '{$stationFromID}')"), 0, 0) or die(mysqli_error($con)); $systemToName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM system WHERE eve_idsystem = (SELECT system_eve_idsystem FROM station WHERE eve_idstation = '{$stationToID}')"), 0, 0) or die(mysqli_error($con)); $systemFromID = utils::mysqli_result(mysqli_query($con, "SELECT system_eve_idsystem FROM station WHERE eve_idstation = '{$stationFromID}'"), 0, 0) or mysqli_error($con); $systemToID = utils::mysqli_result(mysqli_query($con, "SELECT system_eve_idsystem FROM station WHERE eve_idstation = '{$stationToID}'"), 0, 0) or mysqli_error($con); $stationFromName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM station WHERE eve_idstation = '{$stationFromID}'"), 0, 0) or die(mysqli_error($con)); $stationToName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM station WHERE eve_idstation = '{$stationToID}'"), 0, 0) or die(mysqli_error($con)); $transFrom = mysqli_real_escape_string($con, $_GET['tr1']); $transTo = mysqli_real_escape_string($con, $_GET['tr2']); if ($itemID == "") { echo "Invalid item provided"; echo "<a href='regionaltrade.php?character={$character_get}'>Regional Trader Assistant </a>"; die; } //calculate tax $taxcalc = new tax($stationFromID, $stationToID, $con, $character_get, $transFrom, $transTo); $transTaxFrom = $taxcalc->calculateTaxFrom(); $transTaxTo = $taxcalc->calculateTaxTo(); $brokerFeeFrom = $taxcalc->calculateBrokerFrom(); $brokerFeeTo = $taxcalc->calculateBrokerTo(); /*var_dump($toCorpStandingValue); var_dump($fromCorpStandingValue); var_dump($brokerFeeFrom); var_dump($brokerFeeTo); var_dump($transTaxFrom); var_dump($transTaxTo);*/ //echo $key=array_search('1000004',$corpArray); //Get EVE Central Data //getEveCentralData($itemID, $systemFromID, $transTo); $items_list = array(); array_push($items_list, $itemID); //echo "it is"; print_r($items_list); echo "<h4>" . "<b>" . $stationFromName . "</b>" . "(" . $transFrom . ")" . " <i class='fa fa-arrow-circle-o-right fa-fw'></i> " . "<b>" . $stationToName . "</b>" . "(" . $transTo . ")" . "</h4><br>"; echo "<i class='fa fa-chevron-circle-right fa-fw'></i>" . "<b>Broker(origin):</b>" . max(0, number_format(($brokerFeeFrom - 1) * 100, 2)) . "%" . "<i class='fa fa-chevron-circle-right fa-fw'></i>" . "<b>Tax (origin):</b>" . number_format(($transTaxFrom - 1) * 100, 2) . "%" . "<i class='fa fa-chevron-circle-right fa-fw'></i>" . "<b>Broker(dest.):</b>" . abs(number_format(($brokerFeeTo - 1) * 100, 2)) . "%" . "<i class='fa fa-chevron-circle-right fa-fw'></i>" . "<b>Tax (dest.):</b>" . abs(number_format(($transTaxTo - 1) * 100, 2)) . "%" . "<br><br>"; echo "<table class='table table-striped table-bordered table-hover' id='dataTables-example'>"; echo "<thead><tr>" . "<th>" . "Item" . "</th>" . "<th>" . $systemFromName . " " . $transFrom . " price" . "</th>" . "<th>" . "Broker fee" . "</th>" . "<th>" . $systemToName . " " . $transTo . " price" . "</th>" . "<th align = 'right'>" . "Broker fee" . "</th>" . "<th align = 'right'>" . "Transaction tax" . "</th>" . "<th align = 'right'>" . "Raw profit" . "</th>" . "<th align = 'right'>" . "Margin (%)" . "</th></tr></thead>"; foreach ($items_list as $row) { //prices include tax modifiers $priceFrom = getEveCentralData($itemID, $systemFromID, $transFrom); $priceTo = getEveCentralData($itemID, $systemToID, $transTo); $profitRaw = $priceTo * $brokerFeeTo * $transTaxTo - $priceFrom * $brokerFeeFrom; $brokerFeeFromVal = max(100, $priceFrom * ($brokerFeeFrom - 1)); $brokerFeeToVal = $priceTo * (1 - $brokerFeeTo); $transTaxToVal = $priceFrom * (1 - $transTaxTo); $profitRaw > 0 ? $color = "class='success'" : ($color = "class='danger'"); if ($priceFrom > 0 && $priceTo > 0) { $profitMargin = $profitRaw / $priceTo * 100; } else { $profitMargin = "Error"; } mysqli_query($con, "INSERT INTO `trader`.`cache_tool` (`idcache_tool`, `priceFrom`, `priceTo`, `profit`, `margin`, `timestamp`, `item_eveiditem`, `character_eve_idcharacter`, `item_name`, `brokerFrom`, `brokerTo`, `transTo`) \n VALUES (NULL, '{$priceFrom}', '{$priceTo}', '{$profitRaw}', '{$profitMargin}', '{$datetime}', '{$itemID}', '{$character_get}', '{$itemName}', '{$brokerFeeFromVal}', '{$brokerFeeToVal}', '{$transTaxToVal}')") or die(mysqli_error($con)); echo "<tr {$color}>" . "<td>" . "<img src='../Types/" . $itemID . "_32.png'>" . " " . $itemName . "</td>" . "<td align = 'right'>" . number_format($priceFrom) . "</td>" . "<td align = 'right'>" . number_format($brokerFeeFromVal) . "</td>" . "<td align = 'right'>" . number_format($priceTo) . "</td>" . "<td align = 'right'>" . number_format($brokerFeeToVal) . "</td>" . "<td align = 'right'>" . number_format($transTaxToVal) . "</td>" . "<td align = 'right'>" . number_format($profitRaw) . "</td>" . "<td align = 'right'>" . utils::formating_profit(round($profitMargin, 2)) . "</td></tr>"; } echo "</table><br>"; //Add item form ?> <link rel="stylesheet" type="text/css" href="scripts/jquery.autocomplete.css" /> <script type="text/javascript" src="scripts/jquery.js"></script> <script type="text/javascript" src="scripts/jquery.autocomplete.js"></script> <script type="text/javascript"> var jQueryAutocomplete = $.noConflict(true);</script> <script> $(document).ready(function(){ jQueryAutocomplete("#tag4").autocomplete("scripts/autocomplete_i.php", { selectFirst: true }); }); </script> </head> <body> <?php echo " <form name='regional_3' action = 'regionaltrade.php?character={$character_get}&sys1={$stationFromID}&sys2={$stationToID}&tr1={$transFrom}&tr2={$transTo}' method='POST'>"; //send both post and get at same time ?> <label>Add Item: </label> <input name="tag4" type="text" id="tag4" size="50"/> <input type="Submit" value="Submit" name="Submit3" class="btn btn-success" /> </form> <?php } else { if (isset($_POST['Submit'])) { //getEveCentralData(34, 'buy'); if (isset($_POST['tag'])) { $stationFromName = mysqli_real_escape_string($con, $_POST['tag']); } if (isset($_POST['tag2'])) { $stationToName = mysqli_real_escape_string($con, $_POST['tag2']); } $systemFromName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM system WHERE eve_idsystem = " . "(SELECT system_eve_idsystem FROM station WHERE name = '{$stationFromName}')"), 0, 0) or mysqli_error($con); $systemToName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM system WHERE eve_idsystem = " . "(SELECT system_eve_idsystem FROM station WHERE name = '{$stationToName}')"), 0, 0) or mysqli_error($con); $stationFromID = utils::mysqli_result(mysqli_query($con, "SELECT eve_idstation FROM station WHERE name = '{$stationFromName}'"), 0, 0) or die(mysqli_error($con)); $stationToID = utils::mysqli_result(mysqli_query($con, "SELECT eve_idstation FROM station WHERE name = '{$stationToName}'"), 0, 0) or die(mysqli_error($con)); if (isset($_POST['transtype_1'])) { $transtype1 = $_POST['transtype_1']; } if (isset($_POST['transtype_2'])) { $transtype2 = $_POST['transtype_2']; } $systemFromID = utils::mysqli_result(mysqli_query($con, "SELECT eve_idsystem FROM system WHERE name = '{$systemFromName}'"), 0, 0); $systemToID = utils::mysqli_result(mysqli_query($con, "SELECT eve_idsystem FROM system WHERE name = '{$systemToName}'"), 0, 0); //var_dump($systemFromID); //var_dump($systemToID); if ($systemFromID == "" | $systemToID == "") { echo "Invalid solar system provided."; echo "<a href='regionaltrade.php?character={$character_get}'>Regional Trader Assistant </a>"; die; } //User submitted both stations echo "From " . "<b>" . $systemFromName . "</b>" . " to " . "<b>" . $systemToName . "</b>"; ?> <br><link rel="stylesheet" type="text/css" href="scripts/jquery.autocomplete.css" /> <script type="text/javascript" src="scripts/jquery.js"></script> <script type="text/javascript" src="scripts/jquery.autocomplete.js"></script> <script type="text/javascript"> var jQueryAutocomplete = $.noConflict(true);</script> <script> $(document).ready(function(){ jQueryAutocomplete("#tag3").autocomplete("scripts/autocomplete_i.php", { selectFirst: true }); }); </script> </head> <body> <?php echo " <form name='regional_2' action = 'regionaltrade.php?character={$character_get}&sys1={$stationFromID}&sys2={$stationToID}&tr1={$transtype1}&tr2={$transtype2}' method='POST'>"; ?> <label>Item: </label> <input name="tag3" type="text" id="tag3" size="50"/> <input type="Submit" value="Submit" name="Submit2" class="btn btn-success" /> <?php } else { ?> <link rel="stylesheet" type="text/css" href="scripts/jquery.autocomplete.css" /> <script type="text/javascript" src="scripts/jquery.js"></script> <script type="text/javascript" src="scripts/jquery.autocomplete.js"></script> <script type="text/javascript"> var jQueryAutocomplete = $.noConflict(true);</script> <script> $(document).ready(function(){ jQueryAutocomplete("#tag").autocomplete("scripts/autocomplete_s1.php", { selectFirst: true }); }); </script> </head> <body> <?php mysqli_query($con, "DELETE FROM cache_tool WHERE character_eve_idcharacter = '{$character_get}'") or die(mysqli_error($con)); //send both post and get at same time //send both post and get at same time echo " <form name='regional_1' action = 'regionaltrade.php?character={$character_get}' method='POST'>"; ?> <label>Origin: </label> <input name="tag" type="text" id="tag" size="70"/> purchase from: <input type="radio" name="transtype_1" value="buy" checked>buy order <input type="radio" name="transtype_1" value="sell">sell order <br><br> <link rel="stylesheet" type="text/css" href="scripts/jquery.autocomplete.css" /> <script type="text/javascript" src="scripts/jquery.js"></script> <script type="text/javascript" src="scripts/jquery.autocomplete.js"></script> <script type="text/javascript"> var jQueryAutocomplete = $.noConflict(true);</script> <script> $(document).ready(function(){ jQueryAutocomplete("#tag2").autocomplete("scripts/autocomplete_s1.php", { selectFirst: true }); }); <?php ?> </script> <label>Destination: </label> <input name="tag2" type="text" id="tag2" size="70"/> sell as: <input type="radio" name="transtype_2" value="buy">buy order <input type="radio" name="transtype_2" value="sell" checked>sell order <br><br> <input type ="Submit" name="Submit" value="Submit" class="btn btn-success"/> </form> </body> </html> <?php } } } }
function vatreport_download_xls($fields, $month, $year, $startdate, $enddate) { global $CFG, $DB, $USER; require_once("$CFG->libdir/excellib.class.php"); //require_once($CFG->dirroot.'/user/profile/lib.php'); $hierarchy = new hierarchy(); $tax = tax::getInstance(); $filename = clean_filename(get_string('vatreport', 'local_onlinepayment')); $workbook = new MoodleExcelWorkbook('-'); $workbook->send($filename); $worksheet = array(); $worksheet[0] = $workbook->add_worksheet(''); $col = 0; foreach ($fields as $fieldname) { $worksheet[0]->write(0, $col, $fieldname); $col++; } $mysql = "SELECT item.id, item.itemtype, item.moduleid, item.online_courseid, item.item_amount AS amount, tra.orderid, tra.transactionid, tra.timecreated, user.id AS userid, CONCAT(user.firstname, ' ', user.lastname) AS studentname, user.country FROM {local_item} AS item JOIN {local_payment_transaction} AS tra ON tra.orderid = item.orderid JOIN {user} AS user ON user.id = tra.userid WHERE tra.status = 'Success' "; if ($month) { $mysql .= " AND FROM_UNIXTIME(tra.timecreated, '%m') = '{$month}' "; } if ($year) { $mysql .= " AND FROM_UNIXTIME(tra.timecreated, '%Y') = '{$year}' "; } if ($startdate) { $start = date('Y-m-d', $startdate); $mysql .= " AND FROM_UNIXTIME(tra.timecreated, '%Y-%m-%d') >= '{$start}' "; } if ($enddate) { $end = date('Y-m-d', $enddate); $mysql .= " AND FROM_UNIXTIME(tra.timecreated, '%Y-%m-%d') <= '{$end}' "; } $mysql .= " ORDER BY tra.timecreated DESC "; $reports = $DB->get_records_sql($mysql); //$data = array(); $ctrs = array(); foreach ($reports as $report) { $ctrs[$report->id] = $report->country; } $countries = get_string_manager()->get_list_of_countries(false); $euCountries = $tax->get_eu_countries(); $grandtotal = 0; /* ---Group the UK, EU Countries and non EU Countries--- */ //Group UK countries--------------- $i = 1; $sheetrow = 1; $subtotal = 0; $satisfy1 = false; foreach ($ctrs as $key => $ctr) { if ($ctr == 'GB') { $satisfy1 = true; $line = array(); $line[] = $reports[$key]->studentname; //Student Name $line[] = $reports[$key]->amount; $line[] = date('d M, Y', $reports[$key]->timecreated); if ($reports[$key]->itemtype == 'classtype' && $reports[$key]->moduleid) { $line[] = $DB->get_field('local_clclasses', 'fullname', array('id' => $reports[$key]->moduleid)); } else if ($reports[$key]->itemtype == 'mooctype' && $reports[$key]->online_courseid) { $line[] = $DB->get_field('course', 'fullname', array('id' => $reports[$key]->online_courseid)); } // $items = $DB->get_records('local_item', array('orderid'=>$reports[$key]->orderid)); // $modules = array(); // foreach($items as $item){ // if($item->itemtype=='classtype' && $item->moduleid){ // $onlinecourseid = $DB->get_field('local_clclasses', 'onlinecourseid', array('id'=>$item->moduleid));; // } // if($item->itemtype=='mooctype' && $item->online_courseid){ // $onlinecourseid = $item->online_courseid; // } // $course = $DB->get_record('course', array('id'=>$onlinecourseid)); // $modules[] = $course->fullname; // } // $line[] = implode(', ', $modules); $line[] = $countries[$reports[$key]->country]; //Student country $no_vat = false; if ($reports[$key]->itemtype == 'classtype' && $reports[$key]->moduleid) { $local_user = $DB->get_record('local_users', array('userid' => $reports[$key]->userid)); $user_class = $DB->get_record('local_user_clclasses', array('userid' => $reports[$key]->userid, 'classid' => $reports[$key]->moduleid)); $exist = $local_user && $user_class; if ($exist && $local_user->fundsbygovt && !$user_class->fundbyuk) { $no_vat = true; } } if ($no_vat) { $line[] = 'No VAT applied'; $line[] = '0'; $subtotal += '0'; } else if ($tax = $DB->get_record_select('local_tax_rate', "country = '" . $reports[$key]->country . "' AND typeid = 1 AND '" . date('d-m-Y', $reports[$key]->timecreated) . "' BETWEEN FROM_UNIXTIME(startdate, '%d-%m-%Y') AND FROM_UNIXTIME(enddate, '%d-%m-%Y')")) { $line[] = $tax->rate . ' %'; $vatamount = ( $tax->rate / 100 ) * $reports[$key]->amount; $line[] = $vatamount; $subtotal += $vatamount; } else if ($tax = $DB->get_record_select('local_tax_rate', "country = 'all' AND typeid = 1 AND '" . date('d-m-Y', $reports[$key]->timecreated) . "' BETWEEN FROM_UNIXTIME(startdate, '%d-%m-%Y') AND FROM_UNIXTIME(enddate, '%d-%m-%Y')")) { $line[] = $tax->rate . ' %'; $vatamount = ( $tax->rate / 100 ) * $reports[$key]->amount; $line[] = $vatamount; $subtotal += $vatamount; } else { $line[] = '0 %'; $line[] = '0'; $subtotal += '0'; } $col = 0; foreach ($fields as $k => $v) { $worksheet[0]->write($sheetrow, $col, $line[$k]); $col++; } $sheetrow++; $i++; unset($ctrs[$key]); } } if ($satisfy1) { $line = array('', '', '', '', '', 'Sub-Total', $subtotal); $col = 0; foreach ($fields as $k => $v) { $worksheet[0]->write($sheetrow, $col, $line[$k]); $col++; } $sheetrow++; $i++; } $grandtotal += $subtotal; //Group all EU countries--------------- $subtotal = 0; $satisfy2 = false; foreach ($ctrs as $key => $ctr) { if (in_array($ctr, array_keys($euCountries))) { $satisfy2 = true; $line = array(); $line[] = $reports[$key]->studentname; //Student Name $line[] = $reports[$key]->amount; $line[] = date('d M, Y', $reports[$key]->timecreated); if ($reports[$key]->itemtype == 'classtype' && $reports[$key]->moduleid) { $line[] = $DB->get_field('local_clclasses', 'fullname', array('id' => $reports[$key]->moduleid)); } else if ($reports[$key]->itemtype == 'mooctype' && $reports[$key]->online_courseid) { $line[] = $DB->get_field('course', 'fullname', array('id' => $reports[$key]->online_courseid)); } // $items = $DB->get_records('local_item', array('orderid'=>$reports[$key]->orderid)); // $modules = array(); // foreach($items as $item){ // if($item->itemtype=='classtype' && $item->moduleid){ // $onlinecourseid = $DB->get_field('local_clclasses', 'onlinecourseid', array('id'=>$item->moduleid));; // } // if($item->itemtype=='mooctype' && $item->online_courseid){ // $onlinecourseid = $item->online_courseid; // } // $course = $DB->get_record('course', array('id'=>$onlinecourseid)); // $modules[] = $course->fullname; // } // $line[] = implode(', ', $modules); $line[] = $countries[$reports[$key]->country]; //Student country $no_vat = false; if ($reports[$key]->itemtype == 'classtype' && $reports[$key]->moduleid) { $local_user = $DB->get_record('local_users', array('userid' => $reports[$key]->userid)); $user_class = $DB->get_record('local_user_clclasses', array('userid' => $reports[$key]->userid, 'classid' => $reports[$key]->moduleid)); $exist = $local_user && $user_class; if ($exist && $local_user->fundsbygovt && !$user_class->fundbyuk) { $no_vat = true; } } if ($no_vat) { $line[] = 'No VAT applied'; $line[] = '0'; $subtotal += '0'; } else if ($tax = $DB->get_record_select('local_tax_rate', "country = '" . $reports[$key]->country . "' AND typeid = 1 AND '" . date('d-m-Y', $reports[$key]->timecreated) . "' BETWEEN FROM_UNIXTIME(startdate, '%d-%m-%Y') AND FROM_UNIXTIME(enddate, '%d-%m-%Y')")) { $line[] = $tax->rate . ' %'; $vatamount = ( $tax->rate / 100 ) * $reports[$key]->amount; $line[] = $vatamount; $subtotal += $vatamount; } else if ($tax = $DB->get_record_select('local_tax_rate', "country = 'all' AND typeid = 1 AND '" . date('d-m-Y', $reports[$key]->timecreated) . "' BETWEEN FROM_UNIXTIME(startdate, '%d-%m-%Y') AND FROM_UNIXTIME(enddate, '%d-%m-%Y')")) { $line[] = $tax->rate . ' %'; $vatamount = ( $tax->rate / 100 ) * $reports[$key]->amount; $line[] = $vatamount; $subtotal += $vatamount; } else { $line[] = '0 %'; $line[] = '0'; $subtotal += '0'; } $col = 0; foreach ($fields as $k => $v) { $worksheet[0]->write($sheetrow, $col, $line[$k]); $col++; } $sheetrow++; $i++; unset($ctrs[$key]); } } if ($satisfy2) { $line = array('', '', '', '', '', 'Sub-Total', $subtotal); $col = 0; foreach ($fields as $k => $v) { $worksheet[0]->write($sheetrow, $col, $line[$k]); $col++; } $sheetrow++; $i++; } $grandtotal += $subtotal; //Group all Non-EU countries--------------- $subtotal = 0; $satisfy3 = false; foreach ($ctrs as $key => $ctr) { $satisfy3 = true; $line = array(); $line[] = $reports[$key]->studentname; //Student Name $line[] = $reports[$key]->amount; $line[] = date('d M, Y', $reports[$key]->timecreated); if ($reports[$key]->itemtype == 'classtype' && $reports[$key]->moduleid) { $line[] = $DB->get_field('local_clclasses', 'fullname', array('id' => $reports[$key]->moduleid)); } else if ($reports[$key]->itemtype == 'mooctype' && $reports[$key]->online_courseid) { $line[] = $DB->get_field('course', 'fullname', array('id' => $reports[$key]->online_courseid)); } //$items = $DB->get_records('local_item', array('orderid'=>$reports[$key]->orderid)); //$modules = array(); //foreach($items as $item){ // if($item->itemtype=='classtype' && $item->moduleid){ // $onlinecourseid = $DB->get_field('local_clclasses', 'onlinecourseid', array('id'=>$item->moduleid));; // } // if($item->itemtype=='mooctype' && $item->online_courseid){ // $onlinecourseid = $item->online_courseid; // } // $course = $DB->get_record('course', array('id'=>$onlinecourseid)); // $modules[] = $course->fullname; //} //$line[] = implode(', ', $modules); $line[] = $countries[$reports[$key]->country]; //Student country $no_vat = false; if ($reports[$key]->itemtype == 'classtype' && $reports[$key]->moduleid) { $local_user = $DB->get_record('local_users', array('userid' => $reports[$key]->userid)); $user_class = $DB->get_record('local_user_clclasses', array('userid' => $reports[$key]->userid, 'classid' => $reports[$key]->moduleid)); $exist = $local_user && $user_class; if ($exist && $local_user->fundsbygovt && !$user_class->fundbyuk) { $no_vat = true; } } if ($no_vat) { $line[] = 'No VAT applied'; $line[] = '0'; $subtotal += '0'; } else if ($tax = $DB->get_record_select('local_tax_rate', "country = '" . $reports[$key]->country . "' AND typeid = 1 AND '" . date('d-m-Y', $reports[$key]->timecreated) . "' BETWEEN FROM_UNIXTIME(startdate, '%d-%m-%Y') AND FROM_UNIXTIME(enddate, '%d-%m-%Y')")) { $line[] = $tax->rate . ' %'; $vatamount = ( $tax->rate / 100 ) * $reports[$key]->amount; $line[] = $vatamount; $subtotal += $vatamount; } else if ($tax = $DB->get_record_select('local_tax_rate', "country = 'all' AND typeid = 1 AND '" . date('d-m-Y', $reports[$key]->timecreated) . "' BETWEEN FROM_UNIXTIME(startdate, '%d-%m-%Y') AND FROM_UNIXTIME(enddate, '%d-%m-%Y')")) { $line[] = $tax->rate . ' %'; $vatamount = ( $tax->rate / 100 ) * $reports[$key]->amount; $line[] = $vatamount; $subtotal += $vatamount; } else { $line[] = '0 %'; $line[] = '0'; $subtotal += '0'; } $col = 0; foreach ($fields as $k => $v) { $worksheet[0]->write($sheetrow, $col, $line[$k]); $col++; } $sheetrow++; $i++; unset($ctrs[$key]); } if ($satisfy3) { $line = array('', '', '', '', '', 'Sub-Total', $subtotal); $col = 0; foreach ($fields as $k => $v) { $worksheet[0]->write($sheetrow, $col, $line[$k]); $col++; } $sheetrow++; $i++; } $grandtotal += $subtotal; if ($satisfy1 || $satisfy2 || $satisfy3) { $line = array('', '', '', '', '', 'Grand-Total', $grandtotal); $col = 0; foreach ($fields as $k => $v) { $worksheet[0]->write($sheetrow, $col, $line[$k]); $col++; } $sheetrow++; $i++; } $workbook->close(); die; }
function definition() { global $USER, $CFG, $DB, $PAGE; $hierarchy = new hierarchy(); $tax = tax::getInstance(); $mform = $this->_form; $months = $tax->get_months(); $years = $tax->get_years(); $mform->addElement('header', 'settingsheader', get_string('filters', 'local_onlinepayment')); $montharray = array(); $montharray[] = & $mform->createElement('select', 'month', '', $months); $montharray[] = & $mform->createElement('select', 'year', '', $years); $montharray[] = & $mform->createElement('checkbox', 'checkforenable', '', 'Enable'); $mform->addGroup($montharray, 'montharray', get_string('selectmonth', 'local_onlinepayment'), array(' '), false); $mform->disabledIf('month', 'checkforenable'); $mform->disabledIf('year', 'checkforenable'); $mform->addElement('static', 'or', '', '(OR)'); $mform->addElement('date_selector', 'startdate', get_string('startdate', 'local_academiccalendar'), array('optional' => true)); $mform->addElement('date_selector', 'enddate', get_string('enddate', 'local_academiccalendar'), array('optional' => true)); $mform->addElement('hidden', 'page'); $mform->setType('page', PARAM_INT); $mform->addElement('hidden', 'perpage'); $mform->setType('perpage', PARAM_RAW); $mform->addElement('submit', 'submitbutton', 'Search'); }
function update($VAR) { global $VAR; ### Check that user is logged in: if (SESS_LOGGED != '1') { echo "Sorry, you must be logged in!"; } /* check for sub account */ $issubaccount = false; if (!empty($VAR['account_id']) && $VAR['account_id'] != SESS_ACCOUNT) { if ($this->isParentAccount($VAR['account_id'])) { $VAR['id'] = $VAR['account_id']; global $smarty; $issubaccount = true; } else { return false; } } else { $VAR['id'] = SESS_ACCOUNT; $VAR['account_id'] = SESS_ACCOUNT; } $VAR['account_date_last'] = time(); // validate the tax_id require_once PATH_MODULES . 'tax/tax.inc.php'; $taxObj = new tax(); $tax_arr = @$VAR['account_tax_id']; if (is_array($tax_arr)) { foreach ($tax_arr as $country_id => $tax_id) { if ($country_id == $VAR['cid']) { $exempt = @$VAR["account_tax_id_exempt"][$country_id]; if (!($txRs = $taxObj->TaxIdsValidate($country_id, $tax_id, $exempt))) { $this->validated = false; global $C_translate; $this->val_error[] = array('field' => 'account_tax_id', 'field_trans' => $taxObj->errField, 'error' => $C_translate->translate('validate_general', "", "")); } if ($exempt) { $VAR['account_tax_id'] = false; } else { $VAR['account_tax_id'] = $tax_id; } } } } #################################################################### ### Get required static_Vars and validate them... return an array ### w/ ALL errors... #################################################################### require_once PATH_CORE . 'static_var.inc.php'; $static_var = new CORE_static_var(); if (!isset($this->val_error)) { $this->val_error = false; } $all_error = $static_var->validate_form('account', $this->val_error); if ($all_error != false && gettype($all_error) == 'array') { $this->validated = false; } else { $this->validated = true; } #################################################################### # If validation was failed, skip the db insert & # set the errors & origonal fields as Smarty objects, # and change the page to be loaded. #################################################################### if (!$this->validated) { global $smarty; # set the errors as a Smarty Object $smarty->assign('form_validation', $all_error); # set the page to be loaded if (!defined("FORCE_PAGE")) { define('FORCE_PAGE', $VAR['_page_current']); } return; } ### Change password $password_changed = false; if (isset($VAR['account_password']) && $VAR['account_password'] != "") { if (isset($VAR['confirm_password']) && $VAR['account_password'] == $VAR['confirm_password']) { $password = $VAR['account_password']; unset($VAR['account_password']); @($VAR["account_password"] = $password); ### Alert: the password has been changed! global $C_debug, $C_translate; $C_debug->alert($C_translate->translate('password_changed', 'account', '')); $password_changed = true; /* check if new password is ok */ global $C_list; if ($C_list->is_installed('account_password_history')) { include_once PATH_MODULES . 'account_password_history/account_password_history.inc.php'; $accountHistory = new account_password_history(); if (!$accountHistory->getIsPasswordOk(SESS_ACCOUNT, $VAR['account_password'], false)) { $C_debug->alert("The password you have selected has been used recently and cannot be used again at this time for security purposes."); unset($VAR["account_password"]); $password_changed = false; } } } else { ### ERROR: The passwords provided do not match! global $C_debug, $C_translate; $C_debug->alert($C_translate->translate('password_change_match', 'account', '')); unset($VAR["account_password"]); } } else { unset($VAR["account_password"]); } ### Change theme if (isset($VAR['tid']) && $VAR['tid'] != "") { @($VAR["account_theme_id"] = $VAR['tid']); } ### Change Language if (isset($VAR['lid']) && $VAR['lid'] != "") { @($VAR["account_language_id"] = $VAR['lid']); } ### Change country if (isset($VAR['cid']) && $VAR['cid'] != "") { @($VAR["account_country_id"] = $VAR['cid']); } ### Change currency if (isset($VAR['cyid']) && $VAR['cyid'] != "") { @($VAR["account_currency_id"] = $VAR['cyid']); } ### Get the old username ( for db mapping ) $db =& DB(); $sql = 'SELECT username FROM ' . AGILE_DB_PREFIX . 'account WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND id = ' . $db->qstr(SESS_ACCOUNT); $result = $db->Execute($sql); if ($result->RecordCount() > 0) { $old_username = $result->fields['username']; } ### Update the record $this->account_construct(); $type = "update"; $this->method["{$type}"] = split(",", $this->method["{$type}"]); $db = new CORE_database(); $db->update($VAR, $this, $type); /* password logging class */ if ($password_changed && is_object($accountHistory)) { $accountHistory->setNewPassword(SESS_ACCOUNT, $VAR['account_password'], false); } ### Update the static vars: $static_var->update($VAR, 'account', SESS_ACCOUNT); ### Do any db_mapping global $C_list; if ($C_list->is_installed('db_mapping')) { include_once PATH_MODULES . 'db_mapping/db_mapping.inc.php'; $db_map = new db_mapping(); if (!empty($password)) { $db_map->plaintext_password = $password; } else { $db_map->plaintext_password = false; } $db_map->account_edit(SESS_ACCOUNT, $old_username); } /* update groups for subaccount */ if ($issubaccount) { $db =& DB(); $db->Execute(sqlDelete($db, "account_group", "group_id>2 and \n\t\t\t\t(service_id is null or service_id=0 or service_id='') \n\t\t\t\tand account_id=" . $db->qstr($VAR['account_id']))); if (!empty($VAR['groups'])) { global $C_auth; foreach ($VAR['groups'] as $gid => $val) { if ($gid == $val && $C_auth->auth_group_by_id($gid)) { $fields = array('account_id' => $VAR['account_id'], 'group_id' => $gid, 'active' => 1, 'date_orig' => time()); $db->Execute(sqlInsert($db, "account_group", $fields)); } } } } }
<?php /* accounts/taxes/edit-process.php access: accounts_taxes_write Allows existing taxes to be adjusted or new taxes to be added. */ // includes require "../../include/config.php"; require "../../include/amberphplib/main.php"; // custom includes require "../../include/accounts/inc_taxes.php"; if (user_permissions_get('accounts_taxes_write')) { $obj_tax = new tax(); /* Import POST Data */ $obj_tax->id = @security_form_input_predefined("int", "id_tax", 0, ""); $obj_tax->data["name_tax"] = @security_form_input_predefined("any", "name_tax", 1, ""); $obj_tax->data["taxrate"] = @security_form_input_predefined("any", "taxrate", 1, ""); $obj_tax->data["chartid"] = @security_form_input_predefined("int", "chartid", 1, ""); $obj_tax->data["taxnumber"] = @security_form_input_predefined("any", "taxnumber", 1, ""); $obj_tax->data["description"] = @security_form_input_predefined("any", "description", 1, ""); //default settings $obj_tax->data["default_customers"] = @security_form_input_predefined("checkbox", "default_customers", 0, ""); $obj_tax->data["default_vendors"] = @security_form_input_predefined("checkbox", "default_vendors", 0, ""); $obj_tax->data["default_services"] = @security_form_input_predefined("checkbox", "default_services", 0, ""); $obj_tax->data["default_products"] = @security_form_input_predefined("checkbox", "default_products", 0, ""); // only used when adding new taxes
$stationFromID = utils::mysqli_result(mysqli_query($con, "SELECT eve_idstation FROM station WHERE name = '{$fromStation}'"), 0, 0); $stationToID = utils::mysqli_result(mysqli_query($con, "SELECT eve_idstation FROM station WHERE name = '{$toStation}'"), 0, 0); $price_total_b = $quantity_b_calc * $price_unit_b; //this variable does not get decremented $price_total_s = $quantity_s * $price_unit_s; $date_buy = utils::mysqli_result(mysqli_query($con, "SELECT time FROM transaction WHERE idbuy = '{$idbuy_b}'"), 0, 0); $date_sell = utils::mysqli_result(mysqli_query($con, "SELECT time FROM transaction WHERE idbuy = '{$idbuy_s}'"), 0, 0); $datestamp1 = strtotime($date_buy); $datestamp2 = strtotime($date_sell); $characterBuy = utils::mysqli_result(mysqli_query($con, "SELECT name FROM characters WHERE eve_idcharacter = (SELECT character_eve_idcharacter FROM transaction WHERE idbuy ='{$idbuy_b}')"), 0, 0); $characterSell = utils::mysqli_result(mysqli_query($con, "SELECT name FROM characters WHERE eve_idcharacter = (SELECT character_eve_idcharacter FROM transaction WHERE idbuy ='{$idbuy_s}')"), 0, 0); $characterBuyID = utils::mysqli_result(mysqli_query($con, "SELECT eve_idcharacter FROM characters WHERE eve_idcharacter = (SELECT character_eve_idcharacter FROM transaction WHERE idbuy ='{$idbuy_b}')"), 0, 0); $characterSellID = utils::mysqli_result(mysqli_query($con, "SELECT eve_idcharacter FROM characters WHERE eve_idcharacter = (SELECT character_eve_idcharacter FROM transaction WHERE idbuy ='{$idbuy_s}')"), 0, 0); //calculate taxes //include('taxcalc_1.php'); $taxcalc = new tax($stationFromID, $stationToID, $con, $characterSellID, "buy", "sell"); //for now all profits use the seller data $transTaxFrom = $taxcalc->calculateTaxFrom(); $transTaxTo = $taxcalc->calculateTaxTo(); $brokerFeeFrom = $taxcalc->calculateBrokerFrom(); $brokerFeeTo = $taxcalc->calculateBrokerTo(); // echo "found profit"; $price_unit_b_taxed = $price_unit_b * $brokerFeeFrom * $transTaxFrom; $price_total_b_taxed = $price_unit_b_taxed * min($quantity_b, $quantity_s); $price_unit_s_taxed = $price_unit_s * $brokerFeeTo * $transTaxTo; $price_total_s_taxed = $price_unit_s_taxed * min($quantity_s, $quantity_b); /* $brokerFeeFromVal = $priceFrom*($brokerFeeFrom-1); $brokerFeeToVal = $priceTo*(1-$brokerFeeTo); $transTaxToVal = $priceFrom*(1-$transTaxTo); if($brokerFeeFromVal < 100) {$brokerFeeFromVal = 100;} if($brokerFeeToVal < 100) {$brokerFeeToVal = 100;}*/
/** Invoice expiring domains p2 */ function generatedomaininvoice($VAR) { include_once PATH_MODULES . 'tax/tax.inc.php'; $taxObj = new tax(); $db =& DB(); if (is_array($VAR)) { $expire = time(); $rs = $db->Execute(sqlSelect($db, 'service', '*', " id = ::{$VAR['id']}:: AND active=1\n\t \t\t\t\tAND type = 'domain' AND queue = 'none' AND\n\t \t\t\t\t( domain_type = 'register' OR domain_type = 'transfer' OR domain_type = 'renew' ) AND\n\t \t\t\t\t( suspend_billing = 0 OR suspend_billing IS NULL ) ")); $service = $rs->fields; } else { $service = $VAR; } if (empty($service['id'])) { global $C_debug; $C_debug->alert("Unable to generate domain renweal invoice due to domain status."); return false; } # Get the parent invoice details: if (!empty($service['invoice_id'])) { $rs = $db->Execute(sqlSelect($db, 'invoice', '*', " id = {$service['invoice_id']} ", "")); $invoice = $rs->fields; } else { $invoice = false; } # Get the account details: $rs = $db->Execute(sqlSelect($db, 'account', '*', " id = {$service['account_id']} ", "")); $account = $rs->fields; # Get the account price include_once PATH_MODULES . 'host_tld/host_tld.inc.php'; $tldObj = new host_tld(); $tld_arr = $tldObj->price_tld_arr($service['domain_tld'], 'renew', false, false, false, $service['account_id']); foreach ($tld_arr as $term => $price) { break; } # Calculate taxes: $rs = $db->Execute($sql = sqlSelect($db, "host_tld", "taxable", "name = ::{$service['domain_tld']}::")); if ($service['taxable'] || @$rs->fields['taxable']) { $tax_arr = $taxObj->calculate($price, $account["country_id"], $account["state"]); } else { $tax_arr = false; } $total = $price; $tax_amt = 0; if (is_array($tax_arr)) { foreach ($tax_arr as $tx) { $tax_amt += $tx['rate']; } $total += $tax_amt; } # calculate the dates $expire = $service['domain_date_expire'] + $term * 86400; $due_date = $service['domain_date_expire'] - 86400 * 3; # Create the invoice $id = sqlGenID($db, "invoice"); $insert = $db->Execute($sql = sqlInsert($db, "invoice", array('date_orig' => time(), 'date_last' => time(), 'type' => 2, 'process_status' => 0, 'billing_status' => 0, 'suspend_billing' => 0, 'print_status' => 0, 'parent_id' => $service['invoice_id'], 'account_id' => $service['account_id'], 'account_billing_id' => $service['account_billing_id'], 'affiliate_id' => @$invoice['affiliate_id'], 'campaign_id' => @$invoice['campaign_id'], 'reseller_id' => @$invoice['reseller_id'], 'checkout_plugin_id' => @$invoice['checkout_plugin_id'], 'tax_amt' => $tax_amt, 'discount_arr' => serialize(@$discount_arr), 'discount_amt' => @$discount_amt, 'total_amt' => $total, 'billed_amt' => 0, 'billed_currency_id' => DEFAULT_CURRENCY, 'actual_billed_amt' => 0, 'actual_billed_currency_id' => @$invoice['actual_billed_currency_id'], 'notice_count' => 0, 'notice_next_date' => time(), 'notice_max' => MAX_BILLING_NOTICE, 'grace_period' => 0, 'due_date' => $due_date), $id)); # create the invoice item: if ($insert) { $db->Execute($idx = sqlInsert($db, "invoice_item", array('date_orig' => time(), 'invoice_id' => $id, 'account_id' => $service['account_id'], 'service_id' => $service['id'], 'sku' => 'DOMAIN-RENEW', 'quantity' => 1, 'item_type' => 2, 'price_type' => 0, 'price_base' => $price, 'price_setup' => 0, 'domain_type' => 'renew', 'date_start' => $service['domain_date_expire'], 'date_stop' => $expire, 'domain_name' => $service['domain_name'], 'domain_tld' => $service['domain_tld'], 'domain_term' => $term, 'tax_amt' => $tax_amt, 'total_amt' => $price))); # Insert tax records $taxObj->invoice_item($id, $idx, $service['account_id'], @$item_tax_arr); # Update the service record $fields = array('active' => 0); $db->Execute(sqlUpdate($db, "service", $fields, "id = {$service['id']}")); global $C_debug; $C_debug->alert("Generated domain renewal invoice for {$service['domain_name']}.{$service['domain_tld']}"); return $id; } }
<?php /* taxes/delete-process.php access: account_taxes_write Deletes a tax provided that the tax has not been added to any invoices. */ // includes require "../../include/config.php"; require "../../include/amberphplib/main.php"; // custom includes require "../../include/accounts/inc_taxes.php"; if (user_permissions_get('accounts_taxes_write')) { $obj_tax = new tax(); /* Import POST Data */ $obj_tax->id = @security_form_input_predefined("int", "id_tax", 1, ""); // these exist to make error handling work right $obj_tax->data["name_tax"] = @security_form_input_predefined("any", "name_tax", 0, ""); // confirm deletion $obj_tax->data["delete_confirm"] = @security_form_input_predefined("any", "delete_confirm", 1, "You must confirm the deletion"); /* Error Handling */ // make sure the tax actually exists if (!$obj_tax->verify_id()) { log_write("error", "process", "The tax you have attempted to edit - " . $obj_tax->id . " - does not exist in this system."); }
public static function getInstance() { if (!self::$_tax) { self::$_tax = new tax(); } return self::$_tax; }