Beispiel #1
0
<?php

CreateTable('periods', "CREATE TABLE `periods` (\n  `periodno` smallint(6) NOT NULL DEFAULT '0',\n  `lastdate_in_period` date NOT NULL DEFAULT '0000-00-00',\n  PRIMARY KEY (`periodno`),\n  KEY `LastDate_in_Period` (`lastdate_in_period`)\n)", $db);
$_SESSION['DefaultDateFormat'] = 'd/m/Y';
InsertRecord('periods', array('periodno'), array(0), array('periodno', 'lastdate_in_period'), array(0, date('Y-m-t')), $db);
InsertRecord('periods', array('periodno'), array(1), array('periodno', 'lastdate_in_period'), array(1, LastDayOfMonth(DateAdd(date('d/m/Y'), 'm', 1))), $db);
unset($_SESSION['DefaultDateFormat']);
    /*in this case default depreciation calc to the last day of last month - and allow user to select a period */
    if (!isset($_POST['ProcessDate'])) {
        $_POST['ProcessDate'] = Date($_SESSION['DefaultDateFormat'], mktime(0, 0, 0, date('m'), 0, date('Y')));
    } else {
        //ProcessDate is set - make sure it is on the last day of the month selected
        if (!Is_Date($_POST['ProcessDate'])) {
            prnMsg(_('The date is expected to be in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
            $InputError = true;
        } else {
            $_POST['ProcessDate'] = LastDayOfMonth($_POST['ProcessDate']);
        }
    }
} else {
    //depn calc has been run previously
    $AllowUserEnteredProcessDate = false;
    $_POST['ProcessDate'] = LastDayOfMonth(DateAdd(ConvertSQLDate($LastDepnRun[0]), 'd', 28));
}
/* Get list of assets for journal */
$sql = "SELECT fixedassets.assetid,\n\t\t\tfixedassets.description,\n\t\t\tfixedassets.depntype,\n\t\t\tfixedassets.depnrate,\n\t\t\tfixedassets.datepurchased,\n\t\t\tfixedassetcategories.accumdepnact,\n\t\t\tfixedassetcategories.depnact,\n\t\t\tfixedassetcategories.categorydescription,\n\t\t\tSUM(CASE WHEN fixedassettrans.fixedassettranstype='cost' THEN fixedassettrans.amount ELSE 0 END) AS costtotal,\n\t\t\tSUM(CASE WHEN fixedassettrans.fixedassettranstype='depn' THEN fixedassettrans.amount ELSE 0 END) AS depnbfwd\n\t\tFROM fixedassets\n\t\tINNER JOIN fixedassetcategories\n\t\t\tON fixedassets.assetcategoryid=fixedassetcategories.categoryid\n\t\tINNER JOIN fixedassettrans\n\t\t\tON fixedassets.assetid=fixedassettrans.assetid\n\t\tWHERE fixedassettrans.transdate<='" . FormatDateForSQL($_POST['ProcessDate']) . "'\n\t\tGROUP BY fixedassets.assetid,\n\t\t\tfixedassets.description,\n\t\t\tfixedassets.depntype,\n\t\t\tfixedassets.depnrate,\n\t\t\tfixedassets.datepurchased,\n\t\t\tfixedassetcategories.accumdepnact,\n\t\t\tfixedassetcategories.depnact,\n\t\t\tfixedassetcategories.categorydescription\n\t\tORDER BY assetcategoryid, assetid";
$AssetsResult = DB_query($sql, $db);
$InputError = false;
//always hope for the best
if (Date1GreaterThanDate2($_POST['ProcessDate'], Date($_SESSION['DefaultDateFormat']))) {
    prnMsg(_('No depreciation will be committed as the processing date is beyond the current date. The depreciation run can only be run for periods prior to today'), 'warn');
    $InputError = true;
}
if (isset($_POST['CommitDepreciation']) and $InputError == false) {
    $result = DB_Txn_Begin($db);
    $TransNo = GetNextTransNo(44, $db);
    $PeriodNo = GetPeriod($_POST['ProcessDate'], $db);
}
Beispiel #3
0
function GetPadDate($year, $month, $contr_id)
{
$query=mysql_query("select pad_date from paddate where contr_id=".$contr_id." and year=".$year." and month=".$month);
$result=mysql_fetch_row($query);
if (mysql_num_rows($query)==1){return format_date($result[0]);}
else {
$month_bufer=$month;
$year_bufer=$year;	
$query=mysql_query("select * from contracts where contr_id=".$contr_id);
$row=mysql_fetch_array($query);
if ($row['pay_time']>0 and $row['pay_time']<10) {$day='0'.$row['pay_time'];}else{$day=$row['pay_time'];}
switch ($row['pay_month']) {
  case 1:if ($month==1){$pad_date=$day.'-12-'.--$year_bufer;} 
         else {$pad_date=$day.'-'.--$month_bufer.'-'.$year;}break;
  case 2:$pad_date=$day.'-'.$month.'-'.$year;break;
  case 3:if ($month==12){$pad_date=$day.'-01-'.++$year_bufer;} 
         else {$pad_date=$day.'-'.++$month_bufer.'-'.$year;}break;
}
$checkdate=split('[-]',$pad_date);
if ($checkdate[1]=='1'){$checkdate[1]='01';} if ($checkdate[1]=='4'){$checkdate[1]='04';} if ($checkdate[1]=='7'){$checkdate[1]='07';}
if ($checkdate[1]=='2'){$checkdate[1]='02';} if ($checkdate[1]=='5'){$checkdate[1]='05';} if ($checkdate[1]=='8'){$checkdate[1]='08';}
if ($checkdate[1]=='3'){$checkdate[1]='03';} if ($checkdate[1]=='6'){$checkdate[1]='06';} if ($checkdate[1]=='9'){$checkdate[1]='09';}
$pad_date = $checkdate[0].'-'.$checkdate[1].'-'.$checkdate[2];
$checkdate=split('[-]',$pad_date);

if (!checkdate($checkdate[1], $checkdate[0],$checkdate[2])){
  $pad_date= LastDayOfMonth($checkdate[1], $checkdate[2]).'-'.$checkdate[1].'-'.$checkdate[2];
  //Ако датата на падеж е невалидна (напр. 30-то число на февруари), тя се насочва към последния ден на текущия месец (28 или 29 февруари)
}
return $pad_date;
}
}