[0000290] Can't upload files
[fa-stable.git] / admin / db / fiscalyears_db.inc
index cbd4784ee9de60787cf55abce2cc6f65b24e9e6c..669e8c3c91f7fbb00572b45b8d7f72a124a9f4bb 100644 (file)
@@ -71,26 +71,36 @@ function delete_fiscalyear($id)
        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_end_date($date1, $date2)
 {
-       $bdate = date2sql($date);
-       $sql = "SELECT MAX(end) FROM ".TB_PREF."fiscal_year WHERE begin < '$bdate'";
+       $sql = "SELECT MAX(end), MIN(begin) FROM ".TB_PREF."fiscal_year";
+       $result = db_query($sql, "could not retrieve last fiscal years");
+       $row = db_fetch_row($result);
+       if ($row[0] === null)
+               return true;
+       $max = add_days(sql2date($row[0]), 1);
+       $min = add_days(sql2date($row[1]), -1);
+       return ($max === $date1 || $min === $date2);
+}
 
+function next_begin_date()
+{
+       $sql = "SELECT MAX(end) FROM ".TB_PREF."fiscal_year";
        $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);
+       return add_days(sql2date($row[0]), 1);
 }
 
 function check_years_before($date, $closed=false)
@@ -159,13 +169,12 @@ function open_year($year)
 //---------------------------------------------------------------------------------------------
 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";
@@ -236,7 +245,7 @@ function delete_this_fiscalyear($selected_id)
        {
                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;