function clientCalc($cid, $month, &$yen, &$date) { //全ての金額を出すためUpdate、Deleteはしない //過去のデータを削除 //DELETE require 'SQLConnect.php'; //全ての金額を出すためUpdate、Deleteはしない //$sql = "DELETE From `rank_calc_month` WHERE (`rcm_month` ='" . $month . "' and rcm_rclid = '" . $cid . "');"; //print $sql . "<BR><BR>"; //$c_hit = mysql_db_query($dbName,$sql) or die('UPDATE error: '.mysql_errno().', '.mysql_error()); mysql_close($dbHandle); require 'SQLConnect_jas.php'; //対象料金テーブルを取得 if ($cid == 0) { $sql = "SELECT * FROM `rank_keyword`;"; } else { $sql = "SELECT * FROM `rank_keyword` Where(rkw_rclid = '" . $cid . "');"; } //print $sql; //print $sql; //SQL文を実行する $rs = mysql_db_query($dbName, $sql); $rsCount = mysql_num_rows($rs); //レコード数 $yenAll = 0; for ($i = 0; $i <= $rsCount - 1; $i++) { $row = @mysql_fetch_array($rs); //print $row[rkw_client] . "<br>"; //print "開始日:" . $row[rkw_contract_startdate] . "<br>"; //print "終了日:" . $row[rkw_contract_enddate] . "<br><br>"; $yenAll += keywordCalc($month, $row[rkw_id], $row[rkw_contract_startdate], $row[rkw_contract_enddate]); } require 'SQLClose.php'; //print "合計:" . $yenAll . "<br>"; $_POST[rcm_month] = $month; $_POST[rcm_rclid] = $cid; $_POST[rcm_makedatetime] = DateNow(0); $_POST[rcm_yen] = $yenAll; //全ての金額を出すためUpdate、Deleteはしない //DataInsert("rank_calc_month"); $yen = $yenAll; $date = $_POST[rcm_makedatetime]; }
function chargeMake($salesorderid = 0) { require_once 'module.php'; require_once 'capCalc.php'; print "|" . $salesorderid . "<br />"; #print "キーワードの計算をします<br />"; //キャップ金額の取得 if ($_GET[cap] !== "off") { $arrKeywordMinus = capCalc($arrTodayCap); print "<p>キャップ計算完了</p>"; } else { print "<p><b>キャップ金額取得できていません。</b></p>"; } //End if # echo "<pre>"; # var_dump($arrKeywordMinus); # echo ""; # exit; global $adb, $log; global $current_user; $log =& LoggerManager::getLogger('RecurringInvoice'); $log->debug("invoked RecurringInvoice"); /** ▼ ** SEO 成果 製品 KW 情報の取得 ** ▼ ****/ $sql = " SELECT `vtiger_inventoryproductrel`.`lineitem_id`, `invoiceid`, `serviceid`, `seo_kwid`, `outcome` FROM `vtiger_inventoryproductrel` "; $sql .= " INNER JOIN `vtiger_invoice` ON `id` = `invoiceid` "; $sql .= " INNER JOIN `vtiger_service` ON `productid` = `serviceid` "; $sql .= " INNER JOIN `vtiger_crmentity` ON `invoiceid` = `crmid` "; $sql .= " INNER JOIN vtiger_invoice_recurring_info ON `vtiger_invoice`.`salesorderid` = `vtiger_invoice_recurring_info`.`salesorderid` "; $sql .= " WHERE TRUE "; if ($salesorderid !== 0) { $sql .= " AND `vtiger_invoice`.`salesorderid` = {$salesorderid} "; } $sql .= " AND `servicecategory` = 'SEO' "; $sql .= " AND `seo_kwid` != 0 "; # $sql .= " AND `division` = '202:Webコミュ' "; $sql .= " AND `start_date` <= '" . $_POST[end_date] . "' "; #契約開始日 $sql .= " AND `expiry_date` >= '" . $_POST[first_date] . "' "; #契約終了日 $sql .= " AND `invoicedate` <= '" . $_POST[end_date] . "' "; #請求日 $sql .= " AND `invoicedate` >= '" . $_POST[first_date] . "' "; #請求日 $sql .= " AND `deleted` = 0 "; print "<p>成果</p>"; print $sql . "<br />"; $result = $adb->pquery($sql, array()); $no_of_invoice = $adb->num_rows($result); for ($i = 0; $i < $no_of_invoice; $i++) { $intInventoryproductrelId = (int) $adb->query_result($result, $i, 'lineitem_id'); $arrInvoiceSeoFee[$intInventoryproductrelId][rkwid] = $adb->query_result($result, $i, 'seo_kwid'); #KwId $arrInvoiceSeoFee[$intInventoryproductrelId][invoiceid] = $adb->query_result($result, $i, 'invoiceid'); #請求ID $arrInvoiceResultSeoFee[$adb->query_result($result, $i, 'invoiceid')]['outcome'] = $adb->query_result($result, $i, 'outcome'); } //End for if ($no_of_invoice !== 0) { foreach ($arrInvoiceSeoFee as $intInventoryproductrelId => $arrInvoiceSeoFeeValue) { if ($_POST[end_date] <= $_POST['todate']) { //課金額の計算 $arrInvoiceSeoFee[$intInventoryproductrelId][fee] = (int) keywordCalc($_POST[month], $arrInvoiceSeoFeeValue[rkwid], $_POST[first_date], $_POST[end_date], $yahooYen, $googleYen); } else { $arrInvoiceSeoFee[$intInventoryproductrelId][fee] = 0; } //End if $arrInvoiceResultSeoFee[$arrInvoiceSeoFeeValue['invoiceid']][fee] += $arrInvoiceSeoFee[$intInventoryproductrelId][fee]; } //End foreach } //End if /** ▲ ** SEO 成果 製品 KW 情報の取得 ** ▲ ****/ /** ▼ ** SEO 固定 製品 KW 情報の取得 ** ▼ ****/ /* $sql = " SELECT `vtiger_inventoryproductrel`.`lineitem_id`, `invoiceid`, `vtiger_products`.`productid`, `unit_price`, `seo_kwid` FROM `vtiger_inventoryproductrel` "; $sql .= " INNER JOIN `vtiger_invoice` ON `id` = `invoiceid` "; $sql .= " INNER JOIN `vtiger_products` ON `vtiger_inventoryproductrel`.`productid` = `vtiger_products`.`productid` "; $sql .= " INNER JOIN `vtiger_crmentity` ON `invoiceid` = `crmid` "; $sql .= " INNER JOIN vtiger_invoice_recurring_info ON `vtiger_invoice`.`salesorderid` = `vtiger_invoice_recurring_info`.`salesorderid` "; $sql .= " WHERE TRUE "; if($salesorderid !== 0) $sql .= " AND `vtiger_invoice`.`salesorderid` = {$salesorderid} "; $sql .= " AND `start_date` <= '".$_POST[end_date]."' "; $sql .= " AND `expiry_date` >= '".$_POST[first_date]."' "; $sql .= " AND `deleted` = 0 "; print "<p>固定</p>"; print $sql . "<br />"; $result = $adb->pquery($sql, array()); $no_of_invoice = $adb->num_rows($result); for($i=0;$i<$no_of_invoice;$i++) { $intInventoryproductrelId = (int)$adb->query_result($result, $i,'lineitem_id'); $arrInvoiceSeoFee[$intInventoryproductrelId][rkwid] = $adb->query_result($result, $i,'seo_kwid'); #KwId $arrInvoiceSeoFee[$intInventoryproductrelId][invoiceid] = $adb->query_result($result, $i,'invoiceid'); #請求ID $arrInvoiceSeoFee[$intInventoryproductrelId][fee] = $adb->query_result($result, $i,'unit_price'); #請求ID }//End for */ /** ▲ ** SEO 固定 製品 KW 情報の取得 ** ▲ ****/ /** ▼ ** SEO 初期 製品 KW 情報の取得 ** ▼ ****/ /* $sql = " SELECT `vtiger_inventoryproductrel`.`lineitem_id`, `invoiceid`, `vtiger_products`.`productid`, `unit_price`, `seo_kwid` FROM `vtiger_inventoryproductrel` "; $sql .= " INNER JOIN `vtiger_invoice` ON `id` = `invoiceid` "; $sql .= " INNER JOIN `vtiger_products` ON `vtiger_inventoryproductrel`.`productid` = `vtiger_products`.`productid` "; $sql .= " INNER JOIN `vtiger_crmentity` ON `invoiceid` = `crmid` "; $sql .= " INNER JOIN vtiger_invoice_recurring_info ON `vtiger_invoice`.`salesorderid` = `vtiger_invoice_recurring_info`.`salesorderid` "; $sql .= " WHERE TRUE "; if($salesorderid !== 0) $sql .= " AND `vtiger_invoice`.`salesorderid` = {$salesorderid} "; $sql .= " AND `first_fee_date` >= '".$_POST[first_date]."' "; $sql .= " AND `first_fee_date` <= '".$_POST[end_date]."' "; $sql .= " AND `deleted` = 0 "; print "<p>初期</p>"; print $sql . "<br />"; $result = $adb->pquery($sql, array()); $no_of_invoice = $adb->num_rows($result); for($i=0;$i<$no_of_invoice;$i++) { $intInventoryproductrelId = (int)$adb->query_result($result, $i,'lineitem_id'); $arrInvoiceSeoFee[$intInventoryproductrelId][rkwid] = $adb->query_result($result, $i,'seo_kwid'); #KwId $arrInvoiceSeoFee[$intInventoryproductrelId][invoiceid] = $adb->query_result($result, $i,'invoiceid'); #請求ID $arrInvoiceSeoFee[$intInventoryproductrelId][fee] = $adb->query_result($result, $i,'unit_price'); #請求ID }//End for /** ▲ ** SEO 初期 製品 KW 情報の取得 ** ▲ ****/ /** ▼ **/ if (count($arrInvoiceSeoFee) !== 0) { /** ▼ SEO成果の金額反映 **/ foreach ($arrInvoiceSeoFee as $intInventoryproductrelId => $arrInventSeoFeeValue) { if ($arrInventSeoFeeValue[fee] === 0) { continue; } $sqlUpdate = " UPDATE vtiger_inventoryproductrel SET listprice = " . (int) $arrInventSeoFeeValue[fee] . " "; $sqlUpdate .= " , discount_amount = " . (int) $arrKeywordMinus[$arrInventSeoFeeValue[rkwid]] . " "; #キャップ金額の追加 $sqlUpdate .= " WHERE TRUE "; $sqlUpdate .= " AND lineitem_id = {$intInventoryproductrelId} "; print $sqlUpdate . "<br />"; $adb->pquery($sqlUpdate); $arrInvoiceFee[$arrInventSeoFeeValue[invoiceid]] += (int) $arrInventSeoFeeValue[fee]; } //End foreach /** ▲ SEO成果の金額反映 **/ } //End if foreach ($arrInvoiceResultSeoFee as $invoiceid => $arrInvoiceResultSeoFeeValue) { $strOutcome = $arrInvoiceResultSeoFeeValue['outcome']; if ($strOutcome === '固定') { $strOutcome = "成果・固定"; } else { $strOutcome = "成果"; } //End if $strOutcomeUpdateSql = " UPDATE `vtiger_invoice` SET `outcome` = '" . $strOutcome . "' WHERE TRUE AND `invoiceid` = " . $invoiceid . ";"; $adb->pquery($strOutcomeUpdateSql); } }