/** * Start the calculation "in background" * @return \Bootstrap\Response\ButtonRemote */ public function startAjax() { if (Status::isCalculationInProgress()) { return BootstrapUI::buttonRemoteResponse()->text('Already in progress')->disableButton()->refresh(); } Log::info("{$this->getUser('username')} started calculation!"); return BootstrapUI::buttonRemoteResponse()->disableButton()->text('Calculation has started')->after(function () { $calculation = new \Calculation(); $calculation->calculate(); }); }
public function __construct($value = null, $parent = null){ $this->_value = $value; //$this->interprete = new Interprete(); $this->html = html::getInstance(); $this->htmlAttributes = new HtmlAttributes(); $this->_parent = $parent; $this->calculator = Calculation::getInstance(); // $this->_isCalculate = $calculate; }
public function test_afterGetRateRequest() { /** === Test Data === */ $STORE_ID = 2; $STOCK_ID = 4; $COUNTRY_CODE = 'LV'; $RESULT = $this->_mock(\Magento\Framework\DataObject::class); /** === Setup Mocks === */ // $storeId = $result->getStore(); $RESULT->shouldReceive('getStore')->once()->andReturn($STORE_ID); // $stockId = $this->_manStock->getStockIdByStoreId($storeId); $this->mManStock->shouldReceive('getStockIdByStoreId')->once()->andReturn($STOCK_ID); // $wrhs = $this->_repoWrhs->getById($stockId); $mWrhs = $this->_mock(\Praxigento\Warehouse\Data\Entity\Warehouse::class); $this->mRepoWrhs->shouldReceive('getById')->once()->andReturn($mWrhs); // $countryCode = $wrhs->getCountryCode(); $mWrhs->shouldReceive('getCountryCode')->once()->andReturn($COUNTRY_CODE); // $result->setCountryId($countryCode); $RESULT->shouldReceive('setCountryId')->once()->with($COUNTRY_CODE); /** === Call and asserts === */ $res = $this->obj->afterGetRateRequest($this->mSubject, $RESULT); $this->assertEquals($RESULT, $res); }
/** * Save PHPExcel to file * * @param string $pFileName * @throws Exception */ public function save($pFilename = null) { // garbage collect $this->_phpExcel->garbageCollect(); $saveArrayReturnType = Calculation::getArrayReturnType(); Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE); // Open file $fileHandle = fopen($pFilename, 'w'); if ($fileHandle === false) { throw new Exception("Could not open file {$pFilename} for writing."); } // Set PDF $this->_isPdf = true; // Build CSS $this->buildCSS(true); // Generate HTML $html = ''; //$html .= $this->generateHTMLHeader(false); $html .= $this->generateSheetData(); //$html .= $this->generateHTMLFooter(); // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) // Check for paper size and page orientation if (is_null($this->getSheetIndex())) { $orientation = $this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P'; $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); } else { $orientation = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P'; $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); } // Override Page Orientation if (!is_null($this->_orientation)) { $orientation = $this->_orientation == Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P'; } // Override Paper Size if (!is_null($this->_paperSize)) { $printPaperSize = $this->_paperSize; } if (isset(self::$_paperSizes[$printPaperSize])) { $paperSize = self::$_paperSizes[$printPaperSize]; } // Create PDF $pdf = new TCPDF($orientation, 'pt', $paperSize); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->AddPage(); // Set the appropriate font $pdf->SetFont($this->_font); $pdf->writeHTML($html); // Document info $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle()); $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator()); $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject()); $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords()); $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator()); // Write to file fwrite($fileHandle, $pdf->output($pFilename, 'S')); // Close file fclose($fileHandle); Calculation::setArrayReturnType($saveArrayReturnType); }
<?php // delyzerからのアクセス認証キー if (!$_REQUEST["access_key"]) { echo "<?xml version=\"1.0\"?>"; echo "<delyzer>"; echo "<judge>false</judge>"; echo "</delyzer>"; exit; } // クラスファイル読み込み require_once "./Calculation.php"; // 計算オブジェクト精製 $calc = new Calculation($_REQUEST["access_key"]); // リクエストで送ってきた日付の有効性をチェック if (!$calc->isDate($_REQUEST["date"])) { echo "<?xml version=\"1.0\"?>"; echo "<delyzer>"; echo "<judge>false</judge>"; echo "</delyzer>"; exit; } //年月日時(例:2007091816)で渡って来ます $check_date = $_REQUEST["date"]; //今月、前月、前々月の年月を取得 list($next_month_year, $next_month_month) = $calc->getMonthAgoDate($check_date, -1); list($one_month_year, $one_month_month) = $calc->getMonthAgoDate($check_date, 0); list($two_month_year, $two_month_month) = $calc->getMonthAgoDate($check_date, 1); list($three_month_year, $three_month_month) = $calc->getMonthAgoDate($check_date, 2); //print("next_month_year=".$next_month_year."<br>"); //print("next_month_month=".$next_month_month."<br>");
<?php Log::info("Started calculation"); $x = new Calculation(); $x->calculate(); Log::info("Calculation done");
/** * Set the locale code to use for formula translations and any special formatting * * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk") * @return boolean Success or failure */ public static function setLocale($locale = 'en_us') { return Calculation::getInstance()->setLocale($locale); }
/** * Save PHPExcel to file * * @param string $pFileName * @throws Exception */ public function save($pFilename = null) { // garbage collect $this->_phpExcel->garbageCollect(); $saveArrayReturnType = Calculation::getArrayReturnType(); Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE); // Build CSS $this->buildCSS(!$this->_useInlineCss); // Open file $fileHandle = fopen($pFilename, 'w'); if ($fileHandle === false) { throw new Exception("Could not open file {$pFilename} for writing."); } // Write headers fwrite($fileHandle, $this->generateHTMLHeader(!$this->_useInlineCss)); // Write navigation (tabs) if (!$this->_isPdf) { fwrite($fileHandle, $this->generateNavigation()); } // Write data fwrite($fileHandle, $this->generateSheetData()); // Write footer fwrite($fileHandle, $this->generateHTMLFooter()); // Close file fclose($fileHandle); Calculation::setArrayReturnType($saveArrayReturnType); }
/** * Code to execute when this worksheet is unset() * */ public function __destruct() { Calculation::getInstance($this->parent)->clearCalculationCacheForWorksheet($this->title); $this->disconnectCells(); }
/** * Get calculated cell value * * @deprecated Since version 1.7.8 for planned changes to cell for array formula handling * * @param boolean $resetLog Whether the calculation engine logger should be reset or not * @return mixed * @throws Exception */ public function getCalculatedValue($resetLog = true) { //echo 'Cell '.$this->getCoordinate().' value is a '.$this->dataType.' with a value of '.$this->getValue().PHP_EOL; if ($this->dataType == Cell\DataType::TYPE_FORMULA) { try { //echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value'.PHP_EOL; $result = Calculation::getInstance($this->getWorksheet()->getParent())->calculateCellValue($this, $resetLog); //echo $this->getCoordinate().' calculation result is '.$result.PHP_EOL; // We don't yet handle array returns if (is_array($result)) { while (is_array($result)) { $result = array_pop($result); } } } catch (Exception $ex) { if ($ex->getMessage() === 'Unable to access External Workbook' && $this->calculatedValue !== null) { //echo 'Returning fallback value of '.$this->calculatedValue.' for cell '.$this->getCoordinate().PHP_EOL; return $this->calculatedValue; // Fallback for calculations referencing external files. } //echo 'Calculation Exception: '.$ex->getMessage().PHP_EOL; $result = '#N/A'; throw new Calculation\Exception($this->getWorksheet()->getTitle() . '!' . $this->getCoordinate() . ' -> ' . $ex->getMessage()); } if ($result === '#Not Yet Implemented') { //echo 'Returning fallback value of '.$this->calculatedValue.' for cell '.$this->getCoordinate().PHP_EOL; return $this->calculatedValue; // Fallback if calculation engine does not support the formula. } //echo 'Returning calculated value of '.$result.' for cell '.$this->getCoordinate().PHP_EOL; return $result; } elseif ($this->value instanceof RichText) { // echo 'Cell value for '.$this->getCoordinate().' is rich text: Returning data value of '.$this->value.'<br />'; return $this->value->getPlainText(); } // echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->value.'<br />'; return $this->value; }
/** * OFFSET * * Returns a reference to a range that is a specified number of rows and columns from a cell or range of cells. * The reference that is returned can be a single cell or a range of cells. You can specify the number of rows and * the number of columns to be returned. * * @param cellAddress The reference from which you want to base the offset. Reference must refer to a cell or * range of adjacent cells; otherwise, OFFSET returns the #VALUE! error value. * @param rows The number of rows, up or down, that you want the upper-left cell to refer to. * Using 5 as the rows argument specifies that the upper-left cell in the reference is * five rows below reference. Rows can be positive (which means below the starting reference) * or negative (which means above the starting reference). * @param cols The number of columns, to the left or right, that you want the upper-left cell of the result * to refer to. Using 5 as the cols argument specifies that the upper-left cell in the * reference is five columns to the right of reference. Cols can be positive (which means * to the right of the starting reference) or negative (which means to the left of the * starting reference). * @param height The height, in number of rows, that you want the returned reference to be. Height must be a positive number. * @param width The width, in number of columns, that you want the returned reference to be. Width must be a positive number. * @return string A reference to a cell or range of cells */ public static function OFFSET($cellAddress = Null, $rows = 0, $columns = 0, $height = null, $width = null) { $rows = self::flattenSingleValue($rows); $columns = self::flattenSingleValue($columns); $height = self::flattenSingleValue($height); $width = self::flattenSingleValue($width); if ($cellAddress == Null) { return 0; } $args = func_get_args(); $pCell = array_pop($args); if (!is_object($pCell)) { return self::$_errorCodes['reference']; } $sheetName = null; if (strpos($cellAddress, "!")) { list($sheetName, $cellAddress) = explode("!", $cellAddress); } if (strpos($cellAddress, ":")) { list($startCell, $endCell) = explode(":", $cellAddress); } else { $startCell = $endCell = $cellAddress; } list($startCellColumn, $startCellRow) = Cell::coordinateFromString($startCell); list($endCellColumn, $endCellRow) = Cell::coordinateFromString($endCell); $startCellRow += $rows; $startCellColumn = Cell::columnIndexFromString($startCellColumn) - 1; $startCellColumn += $columns; if ($startCellRow <= 0 || $startCellColumn < 0) { return self::$_errorCodes['reference']; } $endCellColumn = Cell::columnIndexFromString($endCellColumn) - 1; if ($width != null && !is_object($width)) { $endCellColumn = $startCellColumn + $width - 1; } else { $endCellColumn += $columns; } $startCellColumn = Cell::stringFromColumnIndex($startCellColumn); if ($height != null && !is_object($height)) { $endCellRow = $startCellRow + $height - 1; } else { $endCellRow += $rows; } if ($endCellRow <= 0 || $endCellColumn < 0) { return self::$_errorCodes['reference']; } $endCellColumn = Cell::stringFromColumnIndex($endCellColumn); $cellAddress = $startCellColumn . $startCellRow; if ($startCellColumn != $endCellColumn || $startCellRow != $endCellRow) { $cellAddress .= ':' . $endCellColumn . $endCellRow; } if ($sheetName !== null) { $pSheet = $pCell->getParent()->getParent()->getSheetByName($sheetName); } else { $pSheet = $pCell->getParent(); } return Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, False); }
public function insertLegAmount($user_id, $total_amount, $amount_type = '') { $obj_arr = $this->getConfigurationEntries(); $tds_db = $obj_arr["tds"]; $service_charge_db = $obj_arr["service_charge"]; $amount_type = $amount_type; $tds_amount = $total_amount * $tds_db / 100; $service_charge = $total_amount * $service_charge_db / 100; $amount_payable = $total_amount - ($tds_amount + $service_charge); //$date_of_sub = date("Y-m-d H:i:s"); $date_of_sub = date('Y-m-d H:i:s'); //========================================= require_once 'Calculation11Product.php'; $obj_calc = new Calculation(); $obj_calc->insertInToLegAmount($user_id, 0, 0, 0, $total_amount, $amount_payable, $tds_amount, $service_charge, $date_of_sub, $amount_type, 0); return TRUE; }
public function confirmRegister($tprefix, $details, $pay_type) { $this->db->trans_begin(); $this->load->model('android/androidregistersubmit'); $reg = new AndroidRegisterSubmit(); $regr = array(); $max_nod_id = $reg->getMaxOrderID($tprefix); $next_order_id = $max_nod_id + 1; $regr['fatherid'] = $this->userNameToID($details["placementusername"], $tprefix); $regr['referral_id'] = $this->userNameToID($details["sponserusername"], $tprefix); $regr['product_id'] = $details["productid"]; $regr['username'] = $details["username"]; $regr['joining_date'] = date('Y-m-d H:i:s'); $child_node = $reg->getChildNodeId($tprefix, $regr['fatherid'], $details["position"]); $updt_login_res = $res_login_update = $reg->updateLoginUser($tprefix, $details["username"], md5($details["password"]), $child_node); if ($res_login_update) { $user_level = $reg->getLevel($tprefix, $regr['fatherid']) + 1; $updt_ft_res = $res_ftindi_update = $reg->updateFTIndividual($tprefix, $regr['fatherid'], $details["position"], $details["username"], $child_node, $user_level, $details["productid"], $next_order_id, $pay_type); if ($res_ftindi_update) { $last_insert_id = $this->userNameToID($details["username"], $tprefix); $regr['userid'] = $last_insert_id; $details["loginuser"] = $this->userNameToID($details["loginuser"], $tprefix); $updt_ft_uni = $reg->insertToUnilevelTree($tprefix, $regr); $insert_user_det_res = $res = $reg->insertUserDetails($tprefix, $regr, $details); $id = $insert_tmp1_res = $res1 = $reg->tmpInsert($tprefix, $last_insert_id, 'L'); $insert_tmp2_res = $res1 = $reg->tmpInsert($tprefix, $last_insert_id, 'R'); $insert_tmp2_res = $res1 = 1; } } $rank_status = $this->getRankStatus($tprefix); $balance_amount = 0; if ($rank_status == "yes") { $referal_count = $this->getReferalCount($tprefix, $regr['referral_id']); $old_rank = $this->getUserRank($tprefix, $regr['referral_id']); $regr['rank'] = $this->getCurrentRankFromRankConfig($tprefix, $referal_count); $new_rank = $regr['rank']; $this->updateUserRank($tprefix, $regr['referral_id'], $new_rank); if ($old_rank != $new_rank) { $balance_amount = $this->balanceAmount($tprefix, $regr['referral_id']); $rank_bonuss = array(); $rank_bonuss = $this->getAllRankDetails($tprefix, $new_rank); $balance_amount = $balance_amount + $rank_bonuss[0]['rank_bonus']; $this->updateUsedEwallet($tprefix, $regr['referral_id'], $balance_amount, "yes"); $this->insertIntoRankHistory($tprefix, $old_rank, $regr['rank'], $regr['referral_id']); } } $module_status = $this->getModuleStatus($tprefix); $product_status = $module_status->product_status; $first_pair = $module_status->first_pair; $referal_status = $module_status->referal_status; if ($referal_status == "yes") { $referal_amount = $this->getReferalAmount($tprefix); if ($product_status == "yes" && $first_pair == "1:1") { require_once 'Calculation11Product.php'; } else { if ($product_status == "no" && $first_pair == "1:1") { require_once 'Calculation11WithOutProduct.php'; } else { if ($product_status == "yes" && $first_pair == "2:1") { require_once 'Calculation21Product.php'; } else { if ($product_status == "no" && $first_pair == "2:1") { require_once 'Calculation21WithOutProduct.php'; } } } } $obj_calc = new Calculation(); $referal_id = $obj_calc->getReferalId($tprefix, $last_insert_id); if ($referal_amount > 0) { $raferal_amount = $balance_amount + $referal_amount; $ref_amt = $obj_calc->insertReferalAmount($tprefix, $referal_id, $referal_amount, $regr['userid']); } } if ($product_status == "yes") { if ($first_pair == "2:1") { require_once 'Calculation21Product.php'; $obj_calc = new Calculation(); $obj_calc->calculateLegCount($tprefix, $regr['userid'], $regr['fatherid'], $regr['product_id'], $details["position"], $regr['userid']); } else { require_once 'Calculation11Product.php'; $obj_calc = new Calculation(); $obj_calc->calculateLegCount($tprefix, $regr['userid'], $regr['fatherid'], $regr['product_id'], $details["position"], $regr['userid']); } } else { if ($first_pair == "2:1") { require_once 'Calculation21WithOutProduct.php'; $obj_calc = new Calculation(); $obj_calc->calculateLegCount($tprefix, $regr['userid'], $regr['fatherid'], $details["position"], $regr['userid']); } else { require_once 'Calculation11WithOutProduct.php'; $obj_calc = new Calculation(); $obj_calc->calculateLegCount($tprefix, $regr['userid'], $regr['fatherid'], $details["position"], $regr['referral_id'], $regr['userid']); } } if ($updt_ft_res && $updt_login_res && $insert_user_det_res && $insert_tmp1_res && $insert_tmp2_res) { //$mobile = $regr['mobile']; $username = $regr['username']; //$password = $regr['pswd']; //$full_name = $regr['full_name']; $site_info = $this->getSiteConfiguration($tprefix); $site_name = $site_info['co_name']; $site_logo = $site_info['logo']; $base_url = base_url(); $tran_code = $reg->getRandTransPasscode($tprefix, 8); $reg->savePassCodes($tprefix, $last_insert_id, $tran_code); if ($details["email"] != "" && $details["email"] != null) { $reg_mail = $this->checkMailStatus($tprefix); if ($reg_mail['reg_mail_status'] == 'yes') { $email = $details["email"]; $mail_content = $reg->getMailBody($tprefix); $subject = "{$site_name} Registration Notification"; $mailBodyDetails = '<html xmlns="https://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="https://fonts.googleapis.com/css?family=Droid+Serif" rel="stylesheet" type="text/css"> <style> margin:0px; padding:0px; </style> </head> <body> <div style="width:80%;padding:40px;border: solid 10px #D0D0D0;margin:50px auto;"> <div style="lwidth:100%;height:62px;border: solid 1px #D0D0D0;background:url(' . $base_url . 'public_html/images/head-bg.png) no-repeat center center;padding:3px 5px 3px 5px;"> <img src="' . $base_url . 'public_html/images/logos/' . $site_logo . '" alt="logo" /> </div> <div style="width:100%;margin:15px 0 0 0;"> <h1 style="font: normal 20px Tahoma, Geneva, sans-serif;">Dear <font color="#e10000">' . $details["name"] . ',</font></h1><br> <p style="font: normal 12px Tahoma, Geneva, sans-serif;text-align:justify;color:#212121;line-height:23px;">' . $mail_content . '</p> <div style="width:400px;height:225px;margin:16px auto;background:url' . $base_url . 'public_html/images/page.png);border: solid 1px #d0d0d0;border-radius: 10px;"> <img src="' . $base_url . 'public_html/images/login-icons.png" width="35px" height="35px" style="float:left;margin-top:10px;margin-left:10px;"/><h2 style="color:#C70716;font:normal 16px Tahoma, Geneva, sans-serif;line-height:34px;margin:10px 0 0 22px;float:left;padding-left: 0px;">LOGIN DETAILS</h2> <div style="clear:both;"></div> <ul style="display:block;margin:14px 0 0 -36px;float:left;"> <li style="list-style:none;font:normal 15px Tahoma, Geneva, sans-serif;color:#212121;margin:5px 0 0 20px;border:1px solid #ccc;background:#fff;width:300px;padding:5px;"><span style="width:150px;float:left;"> Login Link</span><font color="#025BB9"> : <a href=' . "{$base_url}" . '>Click Here</a></font></li> <li style="list-style:none;font:normal 15px Tahoma, Geneva, sans-serif;color:#212121;margin:5px 0 0 20px;border:1px solid #ccc;background:#fff;width:300px;padding:5px;"><span style="width:150px;float:left;">Your UserName</span><font color="#e10000"> : ' . $details["username"] . '</font></li> <li style="list-style:none;font:normal 15px Tahoma, Geneva, sans-serif;color:#212121;margin:5px 0 0 20px;border:1px solid #ccc;background:#fff;width:300px;padding:5px;"><span style="width:150px;float:left;">Your Password</span><font color="#e10000"> : ' . $details["password"] . '</font></li> </ul> </div> <p><br /><br /><br /><br /> </p> </div> </div> </body> </html>'; //$send_mail = $this->sendEmail($mailBodyDetails, $email, $reg_mail); $reg->sendEmail($tprefix, $mailBodyDetails, $regr['userid'], $subject); } } $reg->insertBalanceAmount($tprefix, $regr['userid']); $encr_id = $details["loginuser"]; $encr_id = $this->getEncrypt($encr_id); $this->db->trans_complete(); $msg['user'] = $username; $msg['pwd'] = $details["password"]; $msg['id'] = $encr_id; $msg['status'] = "true"; $msg['tran'] = $tran_code; return $msg; } else { $this->db->trans_rollback(); $encr_id = $details["loginuser"]; $encr_id = $this->getEncrypt($encr_id); $msg['user'] = ""; $msg['pwd'] = ""; $msg['id'] = ""; $msg['status'] = "false"; $msg['tran'] = ""; return $msg; } }
/** * Save PHPExcel to file * * @param string $pFileName * @throws Exception */ public function save($pFilename = null) { // Fetch sheet $sheet = $this->_phpExcel->getSheet($this->_sheetIndex); $saveArrayReturnType = Calculation::getArrayReturnType(); Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE); // Open file $fileHandle = fopen($pFilename, 'w'); if ($fileHandle === false) { throw new Exception("Could not open file {$pFilename} for writing."); } if ($this->_useBOM) { // Write the UTF-8 BOM code fwrite($fileHandle, ""); } // Convert sheet to array $cellsArray = $sheet->toArray('', $this->_preCalculateFormulas); // Write rows to file foreach ($cellsArray as $row) { $this->_writeLine($fileHandle, $row); } // Close file fclose($fileHandle); Calculation::setArrayReturnType($saveArrayReturnType); }
// ユーザ登録種別 define(USER_REGIST_STATUS_PRE_MEMBER, 0); // '仮登録', define(USER_REGIST_STATUS_MEMBER, 1); // '本登録会員', define(USER_REGIST_STATUS_MEMBER_QUIT, 2); // '会員解除', // 不正アクセスチェック //アクセス許可IP $allowIpArray = array("219.111.2.137", "219.111.1.132"); $ip = $_SERVER[REMOTE_ADDR]; if (!in_array($ip, $allowIpArray)) { header("location:http://www.yahoo.co.jp"); exit; } $calc = new Calculation(); $i_male_uriage = 0; // 男性指定日売上 $i_female_uriage = 0; // 女性指定日売上 $i_total_uriage = 0; // 男女指定日売上 $i_man_regist_num = 0; // 男性指定日登録数 $i_female_regist_num = 0; // 女性指定日登録数 $i_total_regist_num = 0; // 男女指定日登録数 $site_code = $_REQUEST['site_cd']; $targetDate = $_REQUEST['target_date']; if (!$site_code) {
/** * Identify whether a string contains a fractional numeric value, * and convert it to a numeric if it is * * @param string &$operand string value to test * @return boolean */ public static function convertToNumberIfFraction(&$operand) { if (preg_match('/^' . self::STRING_REGEXP_FRACTION . '$/i', $operand, $match)) { $sign = $match[1] == '-' ? '-' : '+'; $fractionFormula = '=' . $sign . $match[2] . $sign . $match[3]; $operand = Calculation::getInstance()->_calculateFormulaValue($fractionFormula); return true; } return false; }
<?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * Description of newPHPClass * * @author Web App Develop PHP */ class Calculation { public function addition($a, $b) { echo 'Summation = ', $a + $b; } } $cal1 = new Calculation(); echo $cal1->addition(5, 9);
if ($uid == $response['uid']) { $priority = 5; } } $currentCalculation->init(getRequest('pid'), $uid, $priority, 0, '', 0, getRequest('input')); if (!$currentCalculation->checkVariables()) { handle(ERROR_INPUT . '01'); } $response = $currentCalculation->create(); if ($response === false) { handle(ERROR_SYSTEM . '00'); } handle('0000{"cid":' . $response . '}'); break; case 'renew': $currentCalculation = new Calculation(); $currentCalculation->cid = getRequest('cid'); $response = json_decode($currentCalculation->getData(), true); require_once 'site.class.php'; $uid = Site::getSessionUid(); if ($uid == 0) { handle(ERROR_PERMISSION . '00' . '请先登陆!'); } if ($response['uid'] !== $uid && !checkAuthority(9)) { handle(ERROR_PERMISSION . '00'); } $priority = $response['priority']; if (checkAuthority(9) && getRequest('priority') !== '') { $priority = getRequest('priority'); } $currentCalculation->init($response['pid'], $response['uid'], $priority, (int) getRequest('public'), getRequest('password'), $response['status'], $response['input']);
<?php // delyzerからのアクセス認証キー if (!$_REQUEST["access_key"]) { echo "<?xml version=\"1.0\"?>"; echo "<delyzer>"; echo "<judge>false</judge>"; echo "</delyzer>a"; exit; } // クラスファイル読み込み require_once "./Calculation.php"; // 計算オブジェクト精製 $calc = new Calculation($_REQUEST["access_key"]); //年月日時(yyyymmdd)で渡って来ます $check_date = $_REQUEST["date"]; if (strlen($_REQUEST["date"]) == 6) { // yyyymmで渡ってきた場合 $check_date = $_REQUEST["date"] . "01"; $scope = "month"; } else { $scope = "day"; } // リクエストで送ってきた日付の有効性をチェック if (!$calc->isDate($check_date)) { echo "<?xml version=\"1.0\"?>"; echo "<delyzer>"; echo "<judge>false</judge>b"; echo "</delyzer>"; exit; }
public function precalculateAction() { $x = new Calculation(); $x->calculate(); }
public function push($type, $value, $reference = null) { $this->_stack[$this->_count++] = array('type' => $type, 'value' => $value, 'reference' => $reference); if ($type == 'Function') { $localeFunction = Calculation::_localeFunc($value); if ($localeFunction != $value) { $this->_stack[$this->_count - 1]['localeValue'] = $localeFunction; } } }
public function confirmRegisterNew($regr, $module_status) { $this->load->model('configuration_model'); $this->load->model('registersubmit'); $reg = new registersubmit(); $max_nod_id = $reg->getMaxOrderID(); $next_order_id = $max_nod_id + 1; if ($regr['user_name_type'] == 'dynamic') { $regr['username'] = $reg->getUsername(); } else { $regr['username'] = $regr['user_name_entry']; } $regr['fatherid'] = $reg->obj_vali->userNameToID($regr['fatherid']); $regr['referral_id'] = $reg->obj_vali->userNameToID($regr['referral_name']); if ($regr['state'] != "") { $regr['state'] = $reg->getStateName($this->input->post('state')); } if ($this->validateRegisterData($regr, $module_status)) { $child_node = $reg->obj_vali->getChildNodeId($regr['fatherid'], $regr['position']); $updt_login_res = $res_login_update = $reg->updateLoginUser($regr['username'], md5($regr['pswd']), $child_node); if ($res_login_update) { $user_level = $reg->getLevel($regr['fatherid']) + 1; $updt_ft_res = $res_ftindi_update = $reg->updateFTIndividual($regr['fatherid'], $regr['position'], $regr['username'], $child_node, $next_order_id, $regr['by_using'], $user_level, $regr['prodcut_id']); if ($res_ftindi_update) { $last_insert_id = $reg->obj_vali->userNameToID($regr['username']); //echo "......vvv";die(); $pin_status = $module_status['pin_status']; $pin_status; $regr['userid'] = $last_insert_id; $updt_ft_uni = $reg->insertToUnilevelTree($regr); $insert_user_det_res = $res = $reg->insertUserDetails($regr); $id = $insert_tmp1_res = $res1 = $reg->tmpInsert($last_insert_id, 'L'); $insert_tmp2_res = $res1 = $reg->tmpInsert($last_insert_id, 'R'); } } $rank_status = $module_status['rank_status']; $product_status = $module_status['product_status']; $first_pair = $module_status['first_pair']; $referal_status = $module_status['referal_status']; $balance_amount = 0; if ($product_status == "yes" && $first_pair == "1:1") { require_once 'Calculation11Product.php'; } else { if ($product_status == "no" && $first_pair == "1:1") { require_once 'Calculation11WithOutProduct.php'; } else { if ($product_status == "yes" && $first_pair == "2:1") { require_once 'Calculation21Product.php'; } else { if ($product_status == "no" && $first_pair == "2:1") { require_once 'Calculation21WithOutProduct.php'; } } } } $obj_calc = new Calculation(); if ($rank_status == "yes") { $referal_count = $reg->obj_vali->getReferalCount($regr['referral_id']); $old_rank = $reg->obj_vali->getUserRank($regr['referral_id']); $regr['rank'] = $reg->obj_vali->getCurrentRankFromRankConfig($referal_count); $new_rank = $regr['rank']; $this->updateUserRank($regr['referral_id'], $new_rank); if ($old_rank != $new_rank) { $rank_bonuss = array(); $rank_bonuss = $this->configuration_model->getAllRankDetails($new_rank); $this->insertIntoRankHistory($old_rank, $regr['rank'], $regr['referral_id']); $date_of_sub = date("Y-m-d H:i:s"); $amount_type = "rank_bonus"; //$level = $this->getUserLevel($regr['referral_id']); $obj_arr = $this->getSettings(); $tds_db = $obj_arr["tds"]; $service_charge_db = $obj_arr["service_charge"]; $rank_amount = $rank_bonuss[0]['rank_bonus']; $tds_amount = $rank_amount * $tds_db / 100; $service_charge = $rank_amount * $service_charge_db / 100; $amount_payable = $rank_amount - ($tds_amount + $service_charge); $obj_calc->insertInToLegAmount($regr['referral_id'], 0, 0, 0, $rank_amount, $amount_payable, $tds_amount, $service_charge, $date_of_sub, $amount_type); } } $product_status = $module_status['product_status']; $first_pair = $module_status['first_pair']; $referal_status = $module_status['referal_status']; if ($referal_status == "yes") { $referal_amount = $this->getReferalAmount(); $referal_id = $obj_calc->getReferalId($last_insert_id); if ($referal_amount > 0) { $raferal_amount = ($balance_amount + $referal_amount) * $regr['quantity']; $ref_amt = $obj_calc->insertReferalAmount($referal_id, $raferal_amount, $regr['userid']); } } if ($product_status == "yes") { if ($first_pair == "2:1") { require_once 'Calculation21Product.php'; $obj_calc = new Calculation(); $obj_calc->calculateLegCount($regr['userid'], $regr['fatherid'], $regr['prodcut_id'], $regr['position'], $regr['userid']); } else { require_once 'Calculation11Product.php'; $obj_calc = new Calculation(); $obj_calc->calculateLegCount($regr['userid'], $regr['fatherid'], $regr['prodcut_id'], $regr['position'], $regr['userid'], $regr['quantity']); } } else { if ($first_pair == "2:1") { require_once 'Calculation21WithOutProduct.php'; $obj_calc = new Calculation(); $obj_calc->calculateLegCount($regr['userid'], $regr['fatherid'], $regr['position'], $regr['userid']); } else { require_once 'Calculation11WithOutProduct.php'; $obj_calc = new Calculation(); $obj_calc->calculateLegCount($regr['userid'], $regr['fatherid'], $regr['position'], $regr['referral_id'], $regr['userid']); } } $level_count = $this->getLevelCount(); if ($level_count > 0) { if ($module_status['sponsor_commission_status'] == 'yes') { $obj_calc->calculateLevelCommission($regr['userid'], $referal_id, $regr['prodcut_id']); } } if ($updt_ft_res && $updt_login_res && $insert_user_det_res && $insert_tmp1_res && $insert_tmp2_res) { $mobile = $regr['mobile']; $username = $regr['username']; $password = $regr['pswd']; $full_name = $regr['full_name']; $site_info = $this->obj_config->getSiteConfiguration(); $site_name = $site_info['co_name']; $site_logo = $site_info['logo']; $base_url = base_url(); $tran_code = $reg->getRandTransPasscode(8); $reg->savePassCodes($last_insert_id, $tran_code); if ($regr['email'] != "" && $regr['email'] != null) { $reg_mail = $this->checkMailStatus(); if ($reg_mail['reg_mail_status'] == 'yes') { $email = $regr['email']; $mail_content = $this->obj_vali->getMailBody(); $subject = "{$site_name} Registration Notification"; $mailBodyDetails = '<html xmlns="https://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="https://fonts.googleapis.com/css?family=Droid+Serif" rel="stylesheet" type="text/css"> <style> margin:0px; padding:0px; </style> </head> <body> <div style="width:80%;padding:40px;border: solid 10px #D0D0D0;margin:50px auto;"> <div style="min-height: 62px;border: solid 1px #d0d0d0;background: url(' . $base_url . 'public_html/images/head-bg.png) no-repeat center center;padding: 0px!important;"> <img src="' . $base_url . 'public_html/images/logos/' . $site_logo . '" alt="logo" style="width: 114px;margin-top: 10px;margin-left: 10px;"/> </div> <div style="width:100%;margin:15px 0 0 0;"> <h1 style="font: normal 20px Tahoma, Geneva, sans-serif;">Dear <font color="#e10000">' . $full_name . ',</font></h1> <p style="font: normal 12px Tahoma, Geneva, sans-serif;text-align:justify;color:#212121;line-height:23px;">' . $mail_content . '</p> <div style="width:400px;height:225px;margin:16px auto;background:url(' . $base_url . 'public_html/images/page.png);border: solid 1px #d0d0d0;border-radius: 10px;"> <h2 style="color:#C70716;font:normal 16px Tahoma, Geneva, sans-serif;line-height:34px;background:url(' . $base_url . 'public_html/images/login-icons.png) center left no-repeat;background-size: 35px 35px;margin:10px 0 0 22px;float:left;padding-left: 54px;">LOGIN DETAILS</h2> <div style="clear:both;"></div> <ul style="display:block;margin:14px 0 0 0;float:left;"> <li style="list-style:none;font:normal 15px Tahoma, Geneva, sans-serif;color:#212121;margin:5px 0 0 20px;border:1px solid #ccc;background:#fff;width:300px;padding:5px;"><span style="width:150px;float:left;">Login Link</span><font color="#025BB9"> : <a href="http://infinitemlmsoftware.com/soft/binary/login/index/user/' . $username . '" target="_blank">Click Here</a></font></li> <li style="list-style:none;font:normal 15px Tahoma, Geneva, sans-serif;color:#212121;margin:5px 0 0 20px;border:1px solid #ccc;background:#fff;width:300px;padding:5px;"><span style="width:150px;float:left;">Your UserName</span><font color="#e10000"> : ' . $username . '</font></li> <li style="list-style:none;font:normal 15px Tahoma, Geneva, sans-serif;color:#212121;margin:5px 0 0 20px;border:1px solid #ccc;background:#fff;width:300px;padding:5px;"><span style="width:150px;float:left;">Your Password</span><font color="#e10000"> : ' . $password . '</font></li> </ul> </div> </div> </div> </body> </html>'; $this->obj_vali->sendEmail($mailBodyDetails, $last_insert_id, $subject); } } $reg->insertBalanceAmount($regr['userid']); $encr_id = $this->session->userdata('user_id'); $encr_id = $this->getEncrypt($encr_id); $msg['user'] = $username; $msg['pwd'] = $password; $msg['id'] = $encr_id; $msg['status'] = true; $msg['tran'] = $tran_code; //if($using=='exact'){ $user = $msg['user']; $pass = $msg['pwd']; $tran_code = $msg['tran']; $product_status = $module_status['product_status']; $payment_method = 'e-xact'; $user_id = $this->userNameToID($user); if ($product_status == "yes") { $insert_into_sales = $this->insertIntoSalesOrder($user_id, $regr['prodcut_id'], $payment_method, $regr['quantity'], $regr['x_trans_id'], "register"); //$this->insertExactHistory($regr); $reg->commit(); } //} return $msg; } else { $reg->rollBack(); $encr_id = $this->session->userdata('user_id'); $encr_id = $this->getEncrypt($encr_id); $msg['user'] = ""; $msg['pwd'] = ""; $msg['id'] = ""; $msg['status'] = false; $msg['tran'] = ""; return $msg; } if ($msg['status']) { //mail('*****@*****.**','commit', ' starting' );//unc //$reg->commit(); //mail('*****@*****.**','commit', ' ending' );//unc } } }
<?php // delyzerからのアクセス認証キー if (!$_REQUEST["access_key"]) { echo "<?xml version=\"1.0\"?>"; echo "<delyzer>"; echo "<judge>false</judge>"; echo "</delyzer>"; exit; } // クラスファイル読み込み require_once "./Calculation.php"; // 計算オブジェクト精製 $calc = new Calculation($_REQUEST["access_key"]); if (!$calc->isDate($_REQUEST["date"])) { echo "<?xml version=\"1.0\"?>"; echo "<delyzer>"; echo "<judge>false</judge>"; echo "</delyzer>"; exit; } //該当日 $date = $_REQUEST["date"]; //1日後 $tomorrow = date("Ymd", mktime(0, 0, 0, substr($date, 4, 2), substr($date, 6, 2) + 1, substr($date, 0, 4))); //1日前 $yesterday = date("Ymd", mktime(0, 0, 0, substr($date, 4, 2), substr($date, 6, 2) - 1, substr($date, 0, 4))); //1週間前 $week_ago = date("Ymd", mktime(0, 0, 0, substr($date, 4, 2), substr($date, 6, 2) - 7, substr($date, 0, 4))); //当月の最初の日 $current_month = date("Ymd", mktime(0, 0, 0, substr($date, 4, 2), 1, substr($date, 0, 4)));
/** * Get calculated cell value * * @return mixed */ public function getCalculatedValue($resetLog = true) { // echo 'Cell '.$this->getCoordinate().' value is a '.$this->_dataType.' with a value of '.$this->getValue().'<br />'; if (!is_null($this->_calculatedValue) && $this->_dataType == Cell_DataType::TYPE_FORMULA) { try { // echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value<br />'; $result = Calculation::getInstance()->calculateCellValue($this, $resetLog); // echo $this->getCoordinate().' calculation result is '.$result.'<br />'; } catch (Exception $ex) { // echo 'Calculation Exception: '.$ex->getMessage().'<br />'; $result = '#N/A'; throw new Exception($ex->getMessage()); } if (is_string($result) && $result == '#Not Yet Implemented') { // echo 'Returning fallback value of '.$this->_calculatedValue.' for cell '.$this->getCoordinate().'<br />'; return $this->_calculatedValue; // Fallback if calculation engine does not support the formula. } else { // echo 'Returning calculated value of '.$result.' for cell '.$this->getCoordinate().'<br />'; return $result; } } if (is_null($this->_value)) { // echo 'Cell '.$this->getCoordinate().' has no value, formula or otherwise<br />'; return null; } else { if ($this->_dataType != Cell_DataType::TYPE_FORMULA) { // echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->_value.'<br />'; return $this->_value; } else { // echo 'Cell value is a formula: Calculating value<br />'; return Calculation::getInstance()->calculateCellValue($this, $resetLog); } } }
/** * Loads PHPExcel from file into PHPExcel instance * * @param string $pFilename * @param PHPExcel $objPHPExcel * @return PHPExcel * @throws Exception */ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) { // Check if file exists if (!file_exists($pFilename)) { throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Create new PHPExcel while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) { $objPHPExcel->createSheet(); } $objPHPExcel->setActiveSheetIndex($this->_sheetIndex); $fromFormats = array('\\-', '\\ '); $toFormats = array('-', ' '); // Open file $fileHandle = fopen($pFilename, 'r'); if ($fileHandle === false) { throw new Exception("Could not open file {$pFilename} for reading."); } // Loop through file $rowData = array(); $column = $row = ''; // loop through one row (line) at a time in the file while (($rowData = fgets($fileHandle)) !== FALSE) { // convert SYLK encoded $rowData to UTF-8 $rowData = Shared_String::SYLKtoUTF8($rowData); // explode each row at semicolons while taking into account that literal semicolon (;) // is escaped like this (;;) $rowData = explode("\t", str_replace('¤', ';', str_replace(';', "\t", str_replace(';;', '¤', rtrim($rowData))))); $dataType = array_shift($rowData); // Read shared styles if ($dataType == 'P') { $formatArray = array(); foreach ($rowData as $rowDatum) { switch ($rowDatum[0]) { case 'P': $formatArray['numberformat']['code'] = str_replace($fromFormats, $toFormats, substr($rowDatum, 1)); break; case 'E': case 'F': $formatArray['font']['name'] = substr($rowDatum, 1); break; case 'L': $formatArray['font']['size'] = substr($rowDatum, 1); break; case 'S': $styleSettings = substr($rowDatum, 1); for ($i = 0; $i < strlen($styleSettings); ++$i) { switch ($styleSettings[$i]) { case 'I': $formatArray['font']['italic'] = true; break; case 'D': $formatArray['font']['bold'] = true; break; case 'T': $formatArray['borders']['top']['style'] = Style_Border::BORDER_THIN; break; case 'B': $formatArray['borders']['bottom']['style'] = Style_Border::BORDER_THIN; break; case 'L': $formatArray['borders']['left']['style'] = Style_Border::BORDER_THIN; break; case 'R': $formatArray['borders']['right']['style'] = Style_Border::BORDER_THIN; break; } } break; } } $this->_formats['P' . $this->_format++] = $formatArray; // Read cell value data } elseif ($dataType == 'C') { $hasCalculatedValue = false; $cellData = $cellDataFormula = ''; foreach ($rowData as $rowDatum) { switch ($rowDatum[0]) { case 'C': case 'X': $column = substr($rowDatum, 1); break; case 'R': case 'Y': $row = substr($rowDatum, 1); break; case 'K': $cellData = substr($rowDatum, 1); break; case 'E': $cellDataFormula = '=' . substr($rowDatum, 1); // Convert R1C1 style references to A1 style references (but only when not quoted) $temp = explode('"', $cellDataFormula); foreach ($temp as $key => &$value) { // Only count/replace in alternate array entries if ($key % 2 == 0) { preg_match_all('/(R(\\[?-?\\d*\\]?))(C(\\[?-?\\d*\\]?))/', $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); // Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way // through the formula from left to right. Reversing means that we work right to left.through // the formula $cellReferences = array_reverse($cellReferences); // Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent, // then modify the formula to use that new reference foreach ($cellReferences as $cellReference) { $rowReference = $cellReference[2][0]; // Empty R reference is the current row if ($rowReference == '') { $rowReference = $row; } // Bracketed R references are relative to the current row if ($rowReference[0] == '[') { $rowReference = $row + trim($rowReference, '[]'); } $columnReference = $cellReference[4][0]; // Empty C reference is the current column if ($columnReference == '') { $columnReference = $column; } // Bracketed C references are relative to the current column if ($columnReference[0] == '[') { $columnReference = $column + trim($columnReference, '[]'); } $A1CellReference = Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); } } } unset($value); // Then rebuild the formula string $cellDataFormula = implode('"', $temp); $hasCalculatedValue = true; break; } } $columnLetter = Cell::stringFromColumnIndex($column - 1); $cellData = Calculation::_unwrapResult($cellData); // Set cell value $objPHPExcel->getActiveSheet()->getCell($columnLetter . $row)->setValue($hasCalculatedValue ? $cellDataFormula : $cellData); if ($hasCalculatedValue) { $cellData = Calculation::_unwrapResult($cellData); $objPHPExcel->getActiveSheet()->getCell($columnLetter . $row)->setCalculatedValue($cellData); } // Read cell formatting } elseif ($dataType == 'F') { $formatStyle = $columnWidth = $styleSettings = ''; $styleData = array(); foreach ($rowData as $rowDatum) { switch ($rowDatum[0]) { case 'C': case 'X': $column = substr($rowDatum, 1); break; case 'R': case 'Y': $row = substr($rowDatum, 1); break; case 'P': $formatStyle = $rowDatum; break; case 'W': list($startCol, $endCol, $columnWidth) = explode(' ', substr($rowDatum, 1)); break; case 'S': $styleSettings = substr($rowDatum, 1); for ($i = 0; $i < strlen($styleSettings); ++$i) { switch ($styleSettings[$i]) { case 'I': $styleData['font']['italic'] = true; break; case 'D': $styleData['font']['bold'] = true; break; case 'T': $styleData['borders']['top']['style'] = Style_Border::BORDER_THIN; break; case 'B': $styleData['borders']['bottom']['style'] = Style_Border::BORDER_THIN; break; case 'L': $styleData['borders']['left']['style'] = Style_Border::BORDER_THIN; break; case 'R': $styleData['borders']['right']['style'] = Style_Border::BORDER_THIN; break; } } break; } } if ($formatStyle > '' && $column > '' && $row > '') { $columnLetter = Cell::stringFromColumnIndex($column - 1); $objPHPExcel->getActiveSheet()->getStyle($columnLetter . $row)->applyFromArray($this->_formats[$formatStyle]); } if (count($styleData) > 0 && $column > '' && $row > '') { $columnLetter = Cell::stringFromColumnIndex($column - 1); $objPHPExcel->getActiveSheet()->getStyle($columnLetter . $row)->applyFromArray($styleData); } if ($columnWidth > '') { if ($startCol == $endCol) { $startCol = Cell::stringFromColumnIndex($startCol - 1); $objPHPExcel->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth); } else { $startCol = Cell::stringFromColumnIndex($startCol - 1); $endCol = Cell::stringFromColumnIndex($endCol - 1); $objPHPExcel->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth); do { $objPHPExcel->getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth); } while ($startCol != $endCol); } } } else { foreach ($rowData as $rowDatum) { switch ($rowDatum[0]) { case 'C': case 'X': $column = substr($rowDatum, 1); break; case 'R': case 'Y': $row = substr($rowDatum, 1); break; } } } } // Close file fclose($fileHandle); // Return return $objPHPExcel; }
/** * Update references within formulas * * @param string $pFormula Formula to update * @param int $pBefore Insert before this one * @param int $pNumCols Number of columns to insert * @param int $pNumRows Number of rows to insert * @return string Updated formula * @throws Exception */ public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) { // Parse formula into a tree of tokens $tokenisedFormula = Calculation::getInstance()->parseFormula($pFormula); $newCellTokens = $cellTokens = array(); $adjustCount = 0; // Build the translation table of cell tokens foreach ($tokenisedFormula as $token) { $token = $token['value']; if (preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $token, $matches)) { list($column, $row) = Cell::coordinateFromString($token); // Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more $column = Cell::columnIndexFromString($column) + 100000; $row += 10000000; $cellIndex = $column . $row; if (!isset($cellTokens[$cellIndex])) { $newReference = $this->updateCellReference($token, $pBefore, $pNumCols, $pNumRows); if ($newReference !== $token) { $newCellTokens[$cellIndex] = preg_quote($newReference); $cellTokens[$cellIndex] = '/(?<![A-Z])' . preg_quote($token) . '(?!\\d)/i'; ++$adjustCount; } } } } if ($adjustCount == 0) { return $pFormula; } krsort($cellTokens); krsort($newCellTokens); // Update cell references in the formula $formulaBlocks = explode('"', $pFormula); foreach ($formulaBlocks as $i => &$formulaBlock) { // Only count/replace in alternate array entries if ($i % 2 == 0) { $formulaBlock = preg_replace($cellTokens, $newCellTokens, $formulaBlock); } } unset($formulaBlock); // Then rebuild the formula string return implode('"', $formulaBlocks); }
public function calculateRepurchase($user_id, $father_id, $product_id, $position, $count) { require_once 'Calculation11Product.php'; $obj_calc = new Calculation(); $res = $obj_calc->calculateLegCount($user_id, $father_id, $product_id, $position, '', $count); $sponsor_id = $this->val->getSponsorId($user_id); $referal_percentage = $this->val->getReferralAmount($product_id); $product_amount = $this->getProduct($product_id); $referal_amount = $product_amount * ($referal_percentage / 100); $res_ref = $obj_calc->insertReferalAmount($sponsor_id, $referal_amount, $user_id); return $res && $res_ref; }
/** * Loads PHPExcel from file into PHPExcel instance * * @param string $pFilename * @param PHPExcel $objPHPExcel * @return PHPExcel * @throws Exception */ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) { // Check if file exists if (!file_exists($pFilename)) { throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $zip = new ZipArchive(); if ($zip->open($pFilename) === true) { // echo '<h1>Meta Information</h1>'; $xml = simplexml_load_string($zip->getFromName("meta.xml")); $namespacesMeta = $xml->getNamespaces(true); // echo '<pre>'; // print_r($namespacesMeta); // echo '</pre><hr />'; $docProps = $objPHPExcel->getProperties(); $officeProperty = $xml->children($namespacesMeta['office']); foreach ($officeProperty as $officePropertyData) { $officePropertyDC = array(); if (isset($namespacesMeta['dc'])) { $officePropertyDC = $officePropertyData->children($namespacesMeta['dc']); } foreach ($officePropertyDC as $propertyName => $propertyValue) { // echo $propertyName.' = '.$propertyValue.'<hr />'; switch ($propertyName) { case 'title': $docProps->setTitle($propertyValue); break; case 'subject': $docProps->setSubject($propertyValue); break; case 'creator': $docProps->setCreator($propertyValue); break; case 'date': $creationDate = strtotime($propertyValue); $docProps->setCreated($creationDate); break; case 'description': $docProps->setDescription($propertyValue); break; } } $officePropertyMeta = array(); if (isset($namespacesMeta['dc'])) { $officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']); } foreach ($officePropertyMeta as $propertyName => $propertyValue) { $propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']); // echo $propertyName.' = '.$propertyValue.'<br />'; // foreach ($propertyValueAttributes as $key => $value) { // echo $key.' = '.$value.'<br />'; // } // echo '<hr />'; // switch ($propertyName) { case 'keyword': $docProps->setKeywords($propertyValue); break; } } } // echo '<h1>Workbook Content</h1>'; $xml = simplexml_load_string($zip->getFromName("content.xml")); $namespacesContent = $xml->getNamespaces(true); // echo '<pre>'; // print_r($namespacesContent); // echo '</pre><hr />'; $workbook = $xml->children($namespacesContent['office']); foreach ($workbook->body->spreadsheet as $workbookData) { $workbookData = $workbookData->children($namespacesContent['table']); $worksheetID = 0; foreach ($workbookData->table as $worksheetDataSet) { $worksheetData = $worksheetDataSet->children($namespacesContent['table']); // print_r($worksheetData); // echo '<br />'; $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']); // print_r($worksheetDataAttributes); // echo '<br />'; if (isset($this->_loadSheetsOnly) && isset($worksheetDataAttributes['name']) && !in_array($worksheetDataAttributes['name'], $this->_loadSheetsOnly)) { continue; } // echo '<h2>Worksheet '.$worksheetDataAttributes['name'].'</h2>'; // Create new Worksheet $objPHPExcel->createSheet(); $objPHPExcel->setActiveSheetIndex($worksheetID); if (isset($worksheetDataAttributes['name'])) { $worksheetName = (string) $worksheetDataAttributes['name']; $objPHPExcel->getActiveSheet()->setTitle($worksheetName); } $rowID = 1; foreach ($worksheetData as $key => $rowData) { // echo '<b>'.$key.'</b><br />'; switch ($key) { case 'table-row': $columnID = 'A'; foreach ($rowData as $key => $cellData) { // echo '<b>'.$columnID.$rowID.'</b><br />'; $cellDataText = $cellData->children($namespacesContent['text']); $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']); $cellDataTableAttributes = $cellData->attributes($namespacesContent['table']); // echo 'Office Attributes: '; // print_r($cellDataOfficeAttributes); // echo '<br />Table Attributes: '; // print_r($cellDataTableAttributes); // echo '<br />Cell Data Text'; // print_r($cellDataText); // echo '<br />'; // $type = $formatting = $hyperlink = null; $hasCalculatedValue = false; $cellDataFormula = ''; if (isset($cellDataTableAttributes['formula'])) { $cellDataFormula = $cellDataTableAttributes['formula']; $hasCalculatedValue = true; } if (isset($cellDataText->p)) { // echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />'; switch ($cellDataOfficeAttributes['value-type']) { case 'string': $type = Cell_DataType::TYPE_STRING; $dataValue = $cellDataText->p; if (isset($dataValue->a)) { $dataValue = $dataValue->a; $cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']); $hyperlink = $cellXLinkAttributes['href']; } break; case 'boolean': $type = Cell_DataType::TYPE_BOOL; $dataValue = $cellDataText->p == 'TRUE' ? True : False; break; case 'float': $type = Cell_DataType::TYPE_NUMERIC; $dataValue = (double) $cellDataOfficeAttributes['value']; if (floor($dataValue) == $dataValue) { $dataValue = (int) $dataValue; } break; case 'date': $type = Cell_DataType::TYPE_NUMERIC; $dateObj = date_create($cellDataOfficeAttributes['date-value']); list($year, $month, $day, $hour, $minute, $second) = explode(' ', $dateObj->format('Y m d H i s')); $dataValue = Shared_Date::FormattedPHPToExcel($year, $month, $day, $hour, $minute, $second); if ($dataValue != floor($dataValue)) { $formatting = Style_NumberFormat::FORMAT_DATE_XLSX15 . ' ' . Style_NumberFormat::FORMAT_DATE_TIME4; } else { $formatting = Style_NumberFormat::FORMAT_DATE_XLSX15; } break; case 'time': $type = Cell_DataType::TYPE_NUMERIC; $dataValue = Shared_Date::PHPToExcel(strtotime('01-01-1970 ' . implode(':', sscanf($cellDataOfficeAttributes['time-value'], 'PT%dH%dM%dS')))); $formatting = Style_NumberFormat::FORMAT_DATE_TIME4; break; } // echo 'Data value is '.$dataValue.'<br />'; // if (!is_null($hyperlink)) { // echo 'Hyperlink is '.$hyperlink.'<br />'; // } } if ($hasCalculatedValue) { $type = Cell_DataType::TYPE_FORMULA; // echo 'Formula: '.$cellDataFormula.'<br />'; $cellDataFormula = substr($cellDataFormula, strpos($cellDataFormula, ':=') + 1); $temp = explode('"', $cellDataFormula); foreach ($temp as $key => &$value) { // Only replace in alternate array entries (i.e. non-quoted blocks) if ($key % 2 == 0) { $value = preg_replace('/\\[\\.(.*):\\.(.*)\\]/Ui', '$1:$2', $value); $value = preg_replace('/\\[\\.(.*)\\]/Ui', '$1', $value); $value = Calculation::_translateSeparator(';', ',', $value); } } unset($value); // Then rebuild the formula string $cellDataFormula = implode('"', $temp); // echo 'Adjusted Formula: '.$cellDataFormula.'<br />'; } if (!is_null($type)) { $objPHPExcel->getActiveSheet()->getCell($columnID . $rowID)->setValueExplicit($hasCalculatedValue ? $cellDataFormula : $dataValue, $type); if ($hasCalculatedValue) { // echo 'Forumla result is '.$dataValue.'<br />'; $objPHPExcel->getActiveSheet()->getCell($columnID . $rowID)->setCalculatedValue($dataValue); } if ($cellDataOfficeAttributes['value-type'] == 'date' || $cellDataOfficeAttributes['value-type'] == 'time') { $objPHPExcel->getActiveSheet()->getStyle($columnID . $rowID)->getNumberFormat()->setFormatCode($formatting); } if (!is_null($hyperlink)) { $objPHPExcel->getActiveSheet()->getCell($columnID . $rowID)->getHyperlink()->setUrl($hyperlink); } } // Merged cells if (isset($cellDataTableAttributes['number-columns-spanned']) || isset($cellDataTableAttributes['number-rows-spanned'])) { $columnTo = $columnID; if (isset($cellDataTableAttributes['number-columns-spanned'])) { $columnTo = Cell::stringFromColumnIndex(Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-spanned'] - 2); } $rowTo = $rowID; if (isset($cellDataTableAttributes['number-rows-spanned'])) { $rowTo = $rowTo + $cellDataTableAttributes['number-rows-spanned'] - 1; } $cellRange = $columnID . $rowID . ':' . $columnTo . $rowTo; $objPHPExcel->getActiveSheet()->mergeCells($cellRange); } if (isset($cellDataTableAttributes['number-columns-repeated'])) { // echo 'Repeated '.$cellDataTableAttributes['number-columns-repeated'].' times<br />'; $columnID = Cell::stringFromColumnIndex(Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-repeated'] - 2); } ++$columnID; } ++$rowID; break; } } ++$worksheetID; } } } // Return return $objPHPExcel; }