OSB enhancements to date

This commit is contained in:
Deon George
2010-11-30 09:41:08 +11:00
parent 8715a2059b
commit ec6a542bc3
478 changed files with 23423 additions and 9309 deletions

View File

@@ -50,29 +50,30 @@ class product extends OSB_module {
$this->details($VAR);
}
public function details($VAR) { return $this->tmdetails($VAR); }
/**
* Show the product details to the user - used on the order form
*/
public function details($VAR) {
public function tmdetails($VAR) {
global $smarty, $C_auth;
if (empty($VAR['id']))
return false;
$db = &DB();
# Able to view inactive items?
if (! $C_auth->auth_method_by_name('invoice','add'))
$active = '';
else
$active = ' AND active=1';
$result = $db->Execute($sql = sqlSelect($db,'product','*',sprintf('id=::%s::%s',$VAR['id'],$active)));
if (! count($result->RecordCount()))
$result = $this->sql_GetRecords(array('where'=>sprintf('id=%s%s',$VAR['id'],$active)));
if (! count($result))
return false;
$result = array_pop($result);
# Check for group settings
$groups = unserialize($result->fields['group_avail']);
$groups = unserialize($result['group_avail']);
$auth = false;
for ($ii=0; $ii<count($groups); $ii++) {
if ($C_auth->auth_group_by_id($groups[$ii])) {
@@ -82,20 +83,22 @@ class product extends OSB_module {
}
}
if (!$auth)
if (! $auth)
return false;
# Define the DB vars as a Smarty accessible block
$smarty->assign('product',$result->fields);
$smarty->assign('record',$result);
# If trial, get the sku of the trial product:
if($result->fields['price_type'] == '2') {
$trial = $db->Execute(sqlSelect($db,'*','product',sprintf('id=::%s::',$result->fields['price_trial_prod'])));
$smarty->assign('trial',$trial->fields);
if ($result['price_type'] == '2') {
$trial = $this->sql_GetRecords(array('where'=>array('id'=>$result['price_trial_prod'])));
if (count($trial))
$smarty->assign('trial',array_pop($trial));
}
# Get the best price for base, setup, & any attributes:
$this->price_arr($result->fields);
$this->price_arr($result);
$smarty->assign('price',$this->price);
# Get any attributes & attribute pricing:
@@ -323,20 +326,24 @@ class product extends OSB_module {
* @param int $weekday Day of Month for fixed billing
* @param int $week Unused
* @return array
* @todo $temp is a temporary hack to stop the rounding of the dates to the begining of the BILLING_WEEKDAY
*/
public function recurrDates($type,$weekday,$week,$period_date=false) {
public function recurrDates($type,$weekday,$week,$period_date=false,$temp=false) {
# Make the period consistent, eg: Quarterly = Jan-Mar,Apr-Jun; HalfYearly = Jan-Jun,Jul-Dec
$strict = false;
$used_months = 0;
# Round the time integer to a whole day.
if (! $period_date)
$period_date = strtotime('today');
else
$period_date = strtotime(date('Y-m-d',$period_date));
switch ($type) {
# Weekly
case 0:
$period_end = $period_date+(86400*7);
return array('start'=>$period_date,'date'=>$period_date,'end'=>$period_end);
return array('start'=>$period_date,'date'=>$period_date,'end'=>$period_end,'prorate'=>1);
# Monthly
case 1:
@@ -376,6 +383,11 @@ class product extends OSB_module {
return false;
}
if (is_null($weekday) && ! $temp)
$weekday = BILLING_WEEKDAY;
elseif ($temp)
$weekday = date('d',$period_date);
if ($strict && $type > 0 && $type < 5)
$used_months = $inc_months-(($inc_months-(date('n',$period_date)%$inc_months))%$inc_months+1);
@@ -387,7 +399,10 @@ class product extends OSB_module {
$period_end = mktime(0,0,0,date('m',$period_start)+$inc_months,$weekday,date('y',$period_start));
return array('start'=>$period_start,'date'=>$period_date,'end' => $period_end);
$total_time = $period_end-$period_start;
$remain_time = $period_end-$period_date;
return array('start'=>$period_start,'date'=>$period_date,'end'=>$period_end,'prorata'=>round($remain_time/$total_time,4));
}
/**
@@ -398,17 +413,13 @@ class product extends OSB_module {
* @param int $week
* @return float
*/
private function prorate($type,$weekday,$week,$period_start=false) {
public function prorate($type,$weekday,$week,$period_start=false) {
$arr = $this->recurrDates($type,$weekday,$week,$period_start);
if (!$arr)
if (! $arr)
return 0;
$total_time = $arr['end']-$arr['start'];
$remain_time = $arr['end']-$arr['date'];
$percent_remain = ($remain_time/$total_time) ;
return round($percent_remain,4);
else
return $arr['prorata'];
}
/**
@@ -770,5 +781,24 @@ class product extends OSB_module {
$db = new CORE_database;
$db->mass_delete($VAR, $this, "");
}
public function getTranslateField($field) {
static $CACHE = array();
if (! $id = $this->getRecordAttr('id'))
return null;
if (! isset($CACHE[$id][$field])) {
$db = &DB();
$rs = $db->Execute(sqlSelect('product_translate',$field,array('where'=>array('product_id'=>$id))));
if ($rs && $rs->RecordCount() && isset($rs->fields[$field]))
$CACHE[$id][$field] = $rs->fields[$field];
else
$CACHE[$id][$field] = null;
}
return $CACHE[$id][$field];
}
}
?>