/** * Updates database prices from the supplied file * @param $filename string fully qualified filepath and name * @param $options array of options; see declaration for details */ function updatePrices($dbc, $filename, array $options = array()) { $result = array('updated' => array(), 'failed' => array(), 'not_found' => array(), 'warning' => array(), 'disabled' => array(), 'modified' => array()); $updated = array(); // store product_id => array of product codes matched for it $stmts = getPreparedStatements($dbc, $options); $labels = $options['header_labels']; try { $importer = new CsvImporter($filename, true, $labels, ","); $select_only = $options['dry_run'] || $options['disable_only']; while ($data = $importer->get(2000)) { foreach ($data as $entry) { $manufacturer = trim(empty($entry[$labels['manufacturer']['label']]) ? $options['manufacturer'] : $entry[$labels['manufacturer']['label']]); $product_code = trim($entry[$labels['product_code']['label']]); $upc = !$options['upc_update'] || empty($entry[$labels['upc']['label']]) ? null : $entry[$labels['upc']['label']]; $list_price = round_up(getAmount($entry[$labels['list_price']['label']]), 2); $cost_price = isset($entry[$labels['cost_price']['label']]) ? round_up(getAmount($entry[$labels['cost_price']['label']]), 2) : null; $sale_price = round_up(getAmount($entry[$labels['sale_price']['label']]), 2); if ($sale_price >= $list_price) { $list_price = $options['allow_upsell'] ? $sale_price : $list_price; $sale_price = null; } $changed = false; // flag indicating product (or matrix) prices changed if (!$stmts['select_product']->bind_param('ss', $product_code, $manufacturer) || !$stmts['select_product']->execute()) { throw new \RuntimeException("Query failed for manufacturer {$manufacturer} and product code {$product_code}: {$stmts['select_product']->errno} - {$stmts['select_product']->error}"); } $main_product_id = fetch_assoc_stmt($stmts['select_product']); $product_id = false; if ($select_only) { if (is_int($main_product_id)) { $result['updated'][] = "Product prices updated; Manufacturer: {$manufacturer} | Product Code: {$product_code} | List Price: \$" . sprintf('%.2f', $list_price) . " | Cost Price: \$" . sprintf('%.2f', $cost_price) . " | Sale Price: \$" . sprintf('%.2f', $sale_price); $changed = true; } elseif (!$options['ignore_missing']) { $result['not_found'][$product_code] = "Product was either not found or prices did not change; Manufacturer: {$manufacturer} | Product Code: {$product_code}"; } if ($options['update_matrix']) { if (!$stmts['select_matrix']->bind_param('ss', $product_code, $manufacturer) || !$stmts['select_matrix']->execute()) { throw new \RuntimeException("Query failed for manufacturer {$manufacturer} and product code {$product_code}: {$stmts['select_matrix']->errno} - {$stmts['select_matrix']->error}"); } elseif (!empty($product_id = fetch_assoc_stmt($stmts['select_matrix']))) { $result['updated'][] = "Matrix prices updated; Manufacturer: {$manufacturer} | Product Code: {$product_code} | List Price: \$" . sprintf('%.2f', $list_price) . " | Sale Price: \$" . sprintf('%.2f', $sale_price); $changed = true; $updated[$product_id][] = $product_code; // wasn't found as a product, but found as a matrix entry if (array_key_exists($product_code, $result['not_found'])) { unset($result['not_found'][$product_code]); } } elseif (array_key_exists($product_code, $result['not_found'])) { $result['not_found'][$product_code] = "Neither product nor matrix entry not found; Manufacturer: {$manufacturer} | Product Code: {$product_code}"; } } } else { if (!$stmts['update_product']->bind_param('dddsi', $list_price, $cost_price, $sale_price, $upc, $main_product_id) || !$stmts['update_product']->execute()) { throw new \RuntimeException("Query failed for manufacturer {$manufacturer} and product code {$product_code}: {$stmts['update_product']->errno} - {$stmts['update_product']->error}"); } elseif ($stmts['update_product']->affected_rows > 0) { $result['updated'][] = "Product prices updated; Manufacturer: {$manufacturer} | Product Code: {$product_code} | List Price: \$" . sprintf('%.2f', $list_price) . " | Cost Price: \$" . sprintf('%.2f', $cost_price) . " | Sale Price: \$" . sprintf('%.2f', $sale_price); $changed = true; } elseif (!$options['ignore_missing']) { $result['not_found'][$product_code] = "Product was either not found or prices did not change; Manufacturer: {$manufacturer} | Product Code: {$product_code}"; } if ($options['update_matrix']) { if (!$stmts['update_matrix']->bind_param('ddsss', $list_price, $sale_price, $upc, $product_code, $manufacturer) || !$stmts['update_matrix']->execute()) { throw new \RuntimeException("Query failed for manufacturer {$manufacturer} and product code {$product_code}: {$stmts['update_matrix']->errno} - {$stmts['update_matrix']->error}"); } elseif ($stmts['update_matrix']->affected_rows > 0) { if (!$stmts['select_matrix']->bind_param('ss', $product_code, $manufacturer) || !$stmts['select_matrix']->execute()) { throw new \RuntimeException("Query to select product id from matrix table failed for manufacturer {$manufacturer} and product code {$product_code}: {$stmts['select_matrix']->errno} - {$stmts['select_matrix']->error}"); } elseif (empty($product_id = fetch_assoc_stmt($stmts['select_matrix']))) { $result['failed'][] = "Matrix entry not found after updating! Manufacturer: {$manufacturer} | Product Code: {$product_code}"; } else { $result['updated'][] = "Matrix prices updated; Manufacturer: {$manufacturer} | Product Code: {$product_code} | List Price: \$" . sprintf('%.2f', $list_price) . " | Sale Price: \$" . sprintf('%.2f', $sale_price); $changed = true; $updated[$product_id][] = $product_code; // wasn't found as a product, but found as a matrix entry if (array_key_exists($product_code, $result['not_found'])) { unset($result['not_found'][$product_code]); } } } elseif (array_key_exists($product_code, $result['not_found'])) { $result['not_found'][$product_code] = "Neither product nor matrix entry was found or updated; Manufacturer: {$manufacturer} | Product Code: {$product_code}"; } } } // Product was found and updated - update 'date updated' field $id = $main_product_id ? $main_product_id : $product_id; if ($id && empty($result['modified'][$id]) && ($options['update_date_all'] || $changed && $options['update_date'])) { if ($select_only) { $result['modified'][$id] = "Date modified updated for product id {$id}: triggered by {$manufacturer} product {$product_code}"; } elseif (!$stmts['update_date']->bind_param('i', $id) || !$stmts['update_date']->execute()) { throw new \RuntimeException("Update date query failed for manufacturer {$manufacturer} and product code {$product_code}: {$stmts['update_date']->errno} - {$stmts['update_date']->error}"); } else { $result['modified'][$id] = "Date modified updated for product id {$id}: triggered by {$manufacturer} product {$product_code}"; } } } } // TODO option to disable warnings (including display thereof) // Array only contains entries when updating matrix codes, i.e. option_matrix table has been modified accordingly foreach ($updated as $product_id => $product_codes) { // select all product / matrix codes from database for this product if (!$stmts['select_product_codes']->bind_param('ii', $product_id, $product_id) || !$stmts['select_product_codes']->execute()) { throw new \RuntimeException("Query to select product codes while checking for warnings failed for product id {$product_id}: {$stmts['select_product_codes']->errno} - {$stmts['select_product_codes']->error}"); } // disable / warn for any that were not found on the price list $codes = fetch_assoc_stmt($stmts['select_product_codes']); $diff = array_diff(is_array($codes) ? $codes : array($codes), $product_codes); if ($options['disable_products']) { if ($options['dry_run']) { $result['disabled'][$product_id] = $diff; } else { // Disable matrix entries first foreach ($diff as $product_code) { if (!$stmts['disable_matrix']->bind_param('is', $product_id, $product_code) || !$stmts['disable_matrix']->execute()) { throw new \RuntimeException("Failed to disable matrix entry for product {$product_id} - {$product_code}: {$stmts['disable_matrix']->errno} - {$stmts['disable_matrix']->error}"); } elseif ($stmts['disable_matrix']->affected_rows > 0) { $result['disabled'][$product_id][] = $product_code; } else { $result['warning'][$product_id][] = "Matrix entry for product {$product_id} - {$product_code} could not be disabled: it may already be disabled, but you should double-check"; } } // Then disable products that no longer have any enabled matrix options if (!$stmts['disable_product']->bind_param('iii', $product_id, $product_id, $product_id) || !$stmts['disable_product']->execute()) { throw new \RuntimeException("Failed to disable product id {$product_id}: {$stmts['disable_product']->errno} - {$stmts['disable_product']->error}"); } elseif ($stmts['disable_product']->affected_rows > 0) { $result['disabled'][$product_id][] = "Product {$product_id} disabled"; } else { $result['warning'][$product_id][] = "Product {$product_id} was not be disabled: it may either not need to be or already is disabled; you should double-check"; } } } elseif (!empty($diff)) { $result['warning'][$product_id] = $diff; } // Update main product price with the lowest (non-zero) of its enabled matrix options if ($options['update_main_price']) { if (!$stmts['lowest_price']->bind_param('i', $product_id) || !$stmts['lowest_price']->execute()) { throw new \RuntimeException("Failed to fetch lowest matrix price for product {$product_id}: {$stmts['lowest_price']->errno} - {$stmts['lowest_price']->error}"); } $prices = fetch_assoc_stmt($stmts['lowest_price']); if (!empty($prices)) { extract($prices); if (!$stmts['update_main_price']->bind_param('ddi', $price, $sale_price, $product_id) || !$stmts['update_main_price']->execute()) { throw new \RuntimeException("Failed to update main prices for product {$product_id}: {$stmts['update_main_price']->errno} - {$stmts['update_main_price']->error}"); } elseif ($stmts['update_main_price']->affected_rows > 0) { $result['updated'][] = "Main prices for product id {$product_id} set to lowest found in matrix: List Price=\${$price}, Sale Price=\$" . ($sale_price ? $sale_price : '0.00'); } else { $result['warning'][$product_id][] = "Failed to update prices to \${$price} (sale: \$" . ($sale_price ? $sale_price : '0.00') . ") - prices may already be up-to-date"; } } } } } catch (\Exception $e) { $result['error'] = $e->getMessage(); } finally { foreach ($stmts as $stmt) { $stmt->close(); } } // Sort results by key foreach ($result as &$array) { ksort($array); } unset($array); // save puppies return $result; }
function getAmountLabelLong($authMethod) { return getAmount($authMethod) . " " . getCurrencyLabelLong(); }
function checkInPrUser($userId, $mcId, $registeredBy) { $userId = escape($userId); if (!is_numeric($userId)) { return 0; } if (isRegisteredToPr($userId, $mcId)) { displaywarning("User already registered to Pr."); return; } $time = date("Y-m-d H:i:s"); $amtToBeCollected = getAmount("prhead", $mcId); $addUserToPrReg = "INSERT INTO `prhospi_pr_status` VALUES ({$mcId},{$userId},'{$time}','0000-00-00 00:00:00',{$amtToBeCollected},0,'{$registeredBy}')"; $addUserToPrRegQuery = mysql_query($addUserToPrReg) or displayerror(mysql_error()); if (mysql_affected_rows() > 0) { displayinfo("Sucessfully Registered for Pragyan"); return displayPrintOptionForPR($userId); } else { displaywarning("User has not registered to pragyan site"); } return ""; }
var organisme = $("#box_Organisme").val(); var date_virement = $("#txt_virement").val(); var date_tresor = $("#txt_date_tresor").val(); var info_tresor = $("#txt_info_tresor").val(); var montantech = $("#txt_echelon").val()*1; var montantmax = $("#montantmax").val()*1; var tpe = $("#txt_tpe").val(); var id = gup('id'); if (table=="repas"){ var montantfcp = $("#txt_encaissement").val(); var montanteuro = eval(montantfcp/119.332); var restearegler = montantfcp; }else{ <?php print "var details = " . json_encode(getAmount()) . ";\n"; ?> var montantfcp = details['montantfcp']; var montanteuro = details['montanteuro']; var restearegler = details['restearegler']; } if(payeur==''){ message("Veuiller entrer le nom ou l'organisme payeur!"); return false; } if(echelonnage && montantech=='') { message("Montant de l'\351chelon vide"); return false; }
$amt = 0; switch ($op) { case '+': $amt = $num1 + $num2; break; case '-': $amt = $num1 - $num2; break; case '*': $amt = $num1 * $num2; break; case '/': $amt = $num1 / $num2; break; default: throw new Exception('Invalid operator.'); break; } return $amt; } $op = $argv[1]; $num = $argv[2]; for ($i = 0; $i <= $num; $i++) { for ($j = 0; $j <= $num; $j++) { $amt = getAmount($op, $j, $i); echo $amt . ' '; if ($j == $num) { echo "\r\n"; } } }
$result = mysql_query($sql); //Check whether the query was successful or not if ($result) { while ($member = mysql_fetch_assoc($result)) { $productid = $member['id']; $date = $startdate; $html = "<TABLE cellspacing=0 cellpadding=0 height='100%' border=1 width=100%><TR>"; $sql = "SELECT A.id, A.name, B.stock\n\t\t\t\t\tFROM {$_SESSION['DB_PREFIX']}event A\n\t\t\t\t\tLEFT OUTER JOIN {$_SESSION['DB_PREFIX']}eventproductmatrix B\n\t\t\t\t\tON B.productid = {$productid}\n\t\t\t\t\tAND B.eventid = A.id\n\t\t\t\t\tORDER BY name"; $itemresult = mysql_query($sql); //Check whether the query was successful or not if ($itemresult) { while ($itemmember = mysql_fetch_assoc($itemresult)) { $eventid = $itemmember['id']; $sold = getAmount($date, $productid, $eventid, $mode, "S"); $broken = getAmount($date, $productid, $eventid, $mode, "B"); $giveaway = getAmount($date, $productid, $eventid, $mode, "G"); $remaining = $itemmember['stock']; if ($remaining == "") { $remaining = "0"; } if ($remaining <= 10) { $remaining = "<span style='color:red'>{$remaining}</span>"; } $html .= "<TD align=center height='75px' width='" . number_format($count, 2) . "%'>{$sold} / {$remaining}</TD>"; } } $html .= "</TR></TABLE>"; array_push($json, array("id" => $productid . "_" . $date, "color" => "white", "textColor" => "blue", "true_start_date" => "{$date}", "start_date" => $date . " 00:00:00", "end_date" => $date . " 23:59:59", "text" => "<div class='entry'>{$html}</div>", "section_id" => $productid)); } } else { logError($sql . " - " . mysql_error());
public function actionPrview() { global $urlRequestRoot, $sourceFolder, $templateFolder, $cmsFolder, $moduleFolder; $moduleComponentId = $this->moduleComponentId; $scriptsFolder = "{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/scripts"; $imagesFolder = "{$urlRequestRoot}/{$cmsFolder}/{$templateFolder}/common/images"; require_once "{$sourceFolder}/{$moduleFolder}/prhospi/prhospi_common.php"; require_once "{$sourceFolder}/{$moduleFolder}/prhospi/accommodation.php"; if (isset($_GET['subaction']) && $_GET['subaction'] == 'getsuggestions' && isset($_GET['forwhat'])) { // echo getSuggestionsForIdOrEmail(escape($_GET['forwhat'])); exit(0); } if (isset($_POST['printthis']) && isset($_POST['printHiddenId'])) { if ($_POST['printHiddenId'] != "") { $pos = strpos($_POST['printHiddenId'], "printHostelAllotmentBill"); if ($pos == 0) { return printDisclaimer($moduleComponentId, substr(escape($_POST['printHiddenId']), 24), "prhead"); } } } if (isset($_POST['txtFormUserId1']) && $_POST['txtFormUserId1'] != '') { // $detailsGiven=explode("- ",escape($_POST['txtFormUserId1'])); $detailsGiven = escape($_POST['txtFormUserId1']); if (!isset($_POST['refundAmt'])) { displaywarning("Refund Amount not declared"); } else { // if(isset($detailsGiven[1])) checkOutPr($detailsGiven[1],escape($_POST['refundAmt']),$moduleComponentId); if (isset($detailsGiven)) { checkOutPr($detailsGiven, escape($_POST['refundAmt']), $moduleComponentId); } else { displaywarning("Invalid Pragyan Id"); } } } $displayTags = <<<TAG \t<table> <tr> <td><a href="./+prview&subaction=viewRegisteredUser"> <div>View Registrants</div></a></td> <td><a href="./+prview"><div>Add User</div></a></td> </tr> </table> TAG; if (isset($_GET['subaction']) && $_GET['subaction'] == 'viewRegisteredUser') { return $displayTags . displayUsersRegisteredToPr($moduleComponentId); } $inputUser = <<<USER <h2> CHECK IN FORM </h2> <form method="POST" id="prCheckInForm" action="./+Prview"> Enter UserId or Email:<input type="text" name="txtFormUserId" id="txtFormUserId" autofocus autocomplete="off" style="width: 256px" /> <div id="suggestionsBox" style="background-color: white; width: 260px; border: 1px solid black; position: absolute; overflow-y: scroll; max-height: 180px; display: none"></div> <input type="submit" Value="Find User"/> <script type="text/javascript" src="{$urlRequestRoot}/{$cmsFolder}/{$moduleFolder}/prhospi/prregister.js"></script> USER; $userDetails = ""; $displayActions = ""; if (isset($_POST['txtFormUserId']) && $_POST['txtFormUserId'] != '') { $detailsGiven = escape($_POST['txtFormUserId']); if (isset($detailsGiven)) { $userDetails .= submitDetailsForPr($detailsGiven, $moduleComponentId, $this->userId); } else { displaywarning("Invalid Pragyan Id"); } } $amtToCollect = getAmount("prhead", $moduleComponentId); $checkOutFORM = <<<checkOut <hr/> <h2> CHECK OUT FORM </h2> <form method="POST" action="./+prview"> <table border="1"> <tr> <td>Enter UserId or Email:</td> <td><input type="text" name="txtFormUserId1" id="txtFormUserId1" autocomplete="off" style="width: 256px" /> <div id="suggestionsBox1" style="background-color: white; width: 260px; border: 1px solid black; position: absolute; overflow-y: scroll; max-height: 180px; display: none"></div><br/> </td> </tr> <tr> <td>Refund Amount:</td> <td><input type="text" disabled="disabled" name="refundAmt1" value="{$amtToCollect}"/> <input type="hidden" name="refundAmt" value="{$amtToCollect}"/></td> </tr> <tr> <td colspan="2"><input type="submit" Value="Find User"/></td> </tr> </table> <!-- <script type="text/javascript" language="javascript" src="{$scriptsFolder}/ajaxsuggestionbox.js"> </script> <script language="javascript"> var userBox = new SuggestionBox(document.getElementById('txtFormUserId1'), document.getElementById('suggestionsBox1'), "./+prview&subaction=getsuggestions&forwhat=%pattern%"); userBox.loadingImageUrl = '{$imagesFolder}/ajaxloading.gif'; </script>--> </form> checkOut; return $displayTags . $inputUser . $userDetails . $checkOutFORM; }
if (hasValidAddress()) { $address = $_POST["address"]; try { $validaddress = isValidBitcoinAddress($address); } catch (Exception $e) { $validaddress = false; } // Valid Bitcoin address? if ($validaddress) { // Debug info $debugtmp .= ", ADDRESS: " . $address; // Go on, if address check is disabled or address was not used before if ($checkAddress == false || $rewardmanager->lookupRewardByAddress($address) == false) { $mastercoinclient = new MastercoinClient(); // Determine amount $amount = getAmount($request->method); // Debug info $debugtmp .= ", AMOUNT: " . $amount; // Create transaction $transaction = $mastercoinclient->createSimpleSend($address, $curtype, $amount); // Output/funds available? if ($transaction) { $transaction = $mastercoinclient->pushTransaction($transaction); $txid = $transaction->getId(); // Tx successful pushed? if ($txid) { // Store tx $storedtx = $rewardmanager->storeReward($transaction, $request->requestid); // Set cookie storeCookie($txid); // Everything is fine
<?php @session_start(); require_once 'secrets.php'; /******** Taxamo configuration **********/ require_once 'taxamo/lib/Taxamo.php'; function getAmount($price) { $taxamo = new Taxamo(new APIClient($privTocken, 'https://api.taxamo.com')); $transaction_line2 = new Input_transaction_line(); $transaction_line2->amount = $price; $transaction_line2->custom_id = 'line2'; $transaction_line2->product_type = 'e-service'; $transaction = new Input_transaction(); $transaction->currency_code = 'GBP'; // whose currency code ? our or the customers ? //propagate customer's IP address when calling API server-side $transaction->buyer_ip = "92.234.73.59"; $transaction->buyer_credit_card_prefix = "454638489"; // echo '>>>>>>>>'.$_SERVER['REMOTE_ADDR']; $transaction->billing_country_code = 'GB'; $transaction->force_country_code = 'GB'; $transaction->transaction_lines = array($transaction_line2); $resp = $taxamo->calculateTax(array('transaction' => $transaction)); $_SESSION['billing_country_code'] = $resp->transaction->billing_country_code; print_r($resp->transaction); return $resp->transaction; } echo getAmount(100); exit;