1 (edited by cristiart 11/23/2013 06:17:18 pm)

Topic: attachments file view

the attach file view options it's not complete. If you attach 2 or more files the function will only output the last one from the array, and will only display that you have one file attached to your order/invoice/dispatch.... etc

so here my add

in attachment_db.inc i added this function:

 

function get_attachment_string($type, $id)
{
global $path_to_root;
    $str_return = "";    
    $sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no=".db_escape($type)." AND trans_no=".db_escape($id)." ORDER BY trans_no";
    $return = db_query($sql, "Could not retrieve attachments");
    while ($attachment = db_fetch($return))
    {
        if (strlen($str_return))
            $str_return = $str_return . " \n";    
            $str_return .= "<br/>";
        $str_return = $str_return . " - Attached File: <a href='$path_to_root/admin/attachments.php?vw=".$attachment["id"]." ' target='blanc_'>ID: ". $attachment["id"] . " Description ". $attachment["description"]. " - ". $attachment["filename"]."</a>";
    }
    return $str_return;
}

in ui_controls.inc line 179 just after $id = has_attachment($type_no, $trans_no); add

 

    $attach = get_attachment_string($type_no, $trans_no);
    echo $attach;

FA team: the above function needs a bit styling but for now this will do the job.

2 (edited by apmuthu 11/24/2013 12:22:02 pm)

Re: attachments file view

This is a useful addition to the FA core. Hope Joe/Janusz add it.

Also since the function delete_attachment($id) is available in the said file admin/db/attachments_db.inc, it can be used in admin/db/fiscalyears_db.inc to replace lines 198-199 in function delete_attachments_and_comments():

        $sql = "DELETE FROM ".TB_PREF."attachments WHERE  type_no = $type_no AND trans_no = $trans_no";
        db_query($sql, "Could not delete attachment");

with

        delete_attachment($row['id']);

provided the file admin/db/attachments_db.inc has been included beforehand.

Furthermore, the error strings in admin/db/attachments_db.inc need to get into the translation files (*.po/*.mo) as well.

Re: attachments file view

This has been fixed and is available at the stable repository. You can also download the files here and replace them.

ui_controls.inc
attachments_db.inc

Regarding the deletion in fiscal years, then it could not be used. The function only deletes one id, we need to delete all attachment to a specific document type.

/Joe

Re: attachments file view

Line 193 in admin/db/fiscalyears_db.inc :

while ($row = db_fetch($result))

will make sure that all pertinent ids will be deleted one at a time, but in the existing code, all pertinent ids will get deleted in the first pass and then be redundantly executed thereafter.

To truly benefit from a single pass deletion, the function would have to be structured thus:

function delete_attachments_and_comments($type_no, $trans_no)
{
    
    $sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no = $type_no AND trans_no = $trans_no";
    $result = db_query($sql, "Could not retrieve attachments");
    $delflag = false;
    while ($row = db_fetch($result))
    {
        $delflag = true;
        $dir =  company_path(). "/attachments";
        if (file_exists($dir."/".$row['unique_name']))
            unlink($dir."/".$row['unique_name']);
    }
    if ($delflag) {
        $sql = "DELETE FROM ".TB_PREF."attachments WHERE  type_no = $type_no AND trans_no = $trans_no";
        db_query($sql, "Could not delete attachment");
    }
    $sql = "DELETE FROM ".TB_PREF."comments WHERE  type = $type_no AND id = $trans_no";
    db_query($sql, "Could not delete comments");
    $sql = "DELETE FROM ".TB_PREF."refs WHERE  type = $type_no AND id = $trans_no";
    db_query($sql, "Could not delete refs");
}

Re: attachments file view

I don't Think this is necessaey, apmuthu.

We have a 2 liners to fix the deletetion in fiscal year, and really, it is not necessary to make another function to replace this.

/Joe

Re: attachments file view

My last post is not a new function but a rehash of the existing function to avoid redundant passes.

The diff patch for the latest Hg is:

--- old/admin/db/fiscalyears_db.inc    Wed Nov 06 16:43:56 2013
+++ new/admin/db/fiscalyears_db.inc    Tue Dec 10 08:53:50 2013
@@ -190,11 +190,15 @@
     
     $sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no = $type_no AND trans_no = $trans_no";
     $result = db_query($sql, "Could not retrieve attachments");
+    $delflag = false;
     while ($row = db_fetch($result))
     {
+        $delflag = true;
         $dir =  company_path(). "/attachments";
         if (file_exists($dir."/".$row['unique_name']))
             unlink($dir."/".$row['unique_name']);
+    }
+    if ($delflag) {
         $sql = "DELETE FROM ".TB_PREF."attachments WHERE  type_no = $type_no AND trans_no = $trans_no";
         db_query($sql, "Could not delete attachment");
     }    
Post's attachments

fiscal_years_patch.zip 8 kb, 1 downloads since 2013-12-10 

You don't have the permssions to download the attachments of this post.

Re: attachments file view

Ok, sorry apmuthu, I will fix this. Thanks.

/Joe

Re: attachments file view

Thanks Joe - fixed in this commit.