commit_transaction();
}
-function is_date_in_fiscalyears($date)
+function is_date_in_fiscalyears($date, $closed=true)
{
$date = date2sql($date);
$sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE '$date' >= begin AND '$date' <= end";
-
+ if (!$closed)
+ $sql .= " AND closed=0";
$result = db_query($sql, "could not get all fiscal years");
return db_fetch($result) !== false;
}
-function is_bad_begin_date($date)
+function check_begin_date($date="", $check=true)
{
- $bdate = date2sql($date);
- $sql = "SELECT MAX(end) FROM ".TB_PREF."fiscal_year WHERE begin < '$bdate'";
-
+ $sql = "SELECT MAX(end) FROM ".TB_PREF."fiscal_year";
+ if ($date !== "")
+ {
+ $bdate = date2sql($date);
+ $sql .= " WHERE begin < '$bdate'";
+ }
$result = db_query($sql, "could not retrieve last fiscal years");
$row = db_fetch_row($result);
if ($row[0] === null)
return false;
$max = add_days(sql2date($row[0]), 1);
- return ($max !== $date);
+ if ($check)
+ return ($max === $date);
+ else
+ return $max;
}
function check_years_before($date, $closed=false)
//---------------------------------------------------------------------------------------------
function delete_attachments_and_comments($type_no, $trans_no)
{
- global $comp_path;
$sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no = $type_no AND trans_no = $trans_no";
$result = db_query($sql, "Could not retrieve attachments");
while ($row = db_fetch($result))
{
- $dir = $comp_path."/".user_company(). "/attachments";
+ $dir = company_path(). "/attachments";
if (file_exists($dir."/".$row['unique_name']))
unlink($dir."/".$row['unique_name']);
$sql = "DELETE FROM ".TB_PREF."attachments WHERE type_no = $type_no AND trans_no = $trans_no";
{
if ($row['type'] == ST_SALESINVOICE)
{
- $deliveries = get_parent_trans(ST_SALESINVOICE,$row['trans_no']);
+ $deliveries = get_sales_parent_numbers($row['type'], $row['trans_no']);
foreach ($deliveries as $delivery)
{
$sql = "DELETE FROM ".TB_PREF."debtor_trans_details WHERE debtor_trans_no = $delivery AND debtor_trans_type = ".ST_CUSTDELIVERY;