Fixed broken table editor page layout on duplicate record error.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 12 Oct 2009 22:08:03 +0000 (22:08 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 12 Oct 2009 22:08:03 +0000 (22:08 +0000)
gl/includes/db/gl_db_account_types.inc
gl/includes/db/gl_db_accounts.inc
gl/manage/gl_account_classes.php
gl/manage/gl_account_types.php
gl/manage/gl_accounts.php

index 25049c43edb9e907c5e6ced6d0b4b1757d91d087..e82ee8dfa88fffd441609c398d1da4b79a022cd1 100644 (file)
@@ -14,7 +14,7 @@ function add_account_type($id, $name, $class_id, $parent)
        $sql = "INSERT INTO ".TB_PREF."chart_types (id, name, class_id, parent)
                VALUES ($id, ".db_escape($name).", $class_id, $parent)";
 
-       db_query($sql, "could not add account type");
+       return db_query($sql);
 }
 
 function update_account_type($id, $name, $class_id, $parent)
@@ -22,7 +22,7 @@ function update_account_type($id, $name, $class_id, $parent)
     $sql = "UPDATE ".TB_PREF."chart_types SET name=".db_escape($name).",
                class_id=$class_id,     parent=$parent WHERE id = $id";
 
-       db_query($sql, "could not update account type");
+       return db_query($sql, "could not update account type");
 }
 
 function get_account_types($all=false)
@@ -66,7 +66,7 @@ function add_account_class($id, $name, $ctype)
        $sql = "INSERT INTO ".TB_PREF."chart_class (cid, class_name, ctype)
                VALUES ($id, ".db_escape($name).", $ctype)";
 
-       db_query($sql, "could not add account type");
+       return db_query($sql);
 }
 
 function update_account_class($id, $name, $ctype)
@@ -74,7 +74,7 @@ function update_account_class($id, $name, $ctype)
     $sql = "UPDATE ".TB_PREF."chart_class SET class_name=".db_escape($name).",
                ctype=$ctype WHERE cid = $id";
 
-       db_query($sql, "could not update account type");
+       return db_query($sql);
 }
 
 function get_account_classes($all=false)
index ce0a35071852b71d96ecb339f42b899e231c3bee..754e7bc45748e94cc33491052d64b527189ed5d8 100644 (file)
@@ -15,7 +15,7 @@ function add_gl_account($account_code, $account_name, $account_type, $account_co
        $sql = "INSERT INTO ".TB_PREF."chart_master (account_code, account_code2, account_name, account_type)
                VALUES (".db_escape($account_code).", ".db_escape($account_code2).", $account_name, $account_type)";
 
-       db_query($sql, "could not add gl account");
+       return db_query($sql);
 }
 
 function update_gl_account($account_code, $account_name, $account_type, $account_code2)
@@ -25,7 +25,7 @@ function update_gl_account($account_code, $account_name, $account_type, $account
                account_type=$account_type, account_code2=".db_escape($account_code2)
                ." WHERE account_code = '$account_code'";
 
-       db_query($sql, "could not update gl account");
+       return db_query($sql);
 }
 
 function delete_gl_account($code)
index bdc6b9790d54e3ed0c54cd0f951148180a9f533d..70faccdb8818fc06fc2cc400420bacfc20361ed8 100644 (file)
@@ -52,15 +52,16 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
 
        if ($selected_id != -1) 
        {
-               update_account_class($selected_id, $_POST['name'], $_POST['ctype']);
-                       display_notification(_('Selected account class settings has been updated'));
+               if(update_account_class($selected_id, $_POST['name'], $_POST['ctype']))
+                               display_notification(_('Selected account class settings has been updated'));
        } 
        else 
        {
-               add_account_class($_POST['id'], $_POST['name'], $_POST['ctype']);
-                       display_notification(_('New account class has been added'));
+               if(add_account_class($_POST['id'], $_POST['name'], $_POST['ctype'])) {
+                               display_notification(_('New account class has been added'));
+                               $Mode = 'RESET';
+                       }
        }
-               $Mode = 'RESET';
        }
 }
 
index 128438433276e087f16fd4f1495e01dbbfac17c7..b4ca18665f55ce9ea2d70438c53a0c7292333228 100644 (file)
@@ -58,15 +58,16 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
 
        if ($selected_id != -1) 
        {
-               update_account_type($selected_id, $_POST['name'], $_POST['class_id'], $_POST['parent']);
-                       display_notification(_('Selected account type has been updated'));
+               if (update_account_type($selected_id, $_POST['name'], $_POST['class_id'], $_POST['parent']))
+                               display_notification(_('Selected account type has been updated'));
        } 
        else 
        {
-               add_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent']);
-                       display_notification(_('New account type has been added'));
+               if (add_account_type($_POST['id'], $_POST['name'], $_POST['class_id'], $_POST['parent'])) {
+                               display_notification(_('New account type has been added'));
+                               $Mode = 'RESET';
+                       }
        }
-               $Mode = 'RESET';
        }
 }
 
index 4699c5498a941be26d07a7a61e1f74565ae90b8d..718be9bd872f692f7b257154933e348a60c8fe65 100644 (file)
@@ -26,6 +26,7 @@ check_db_has_gl_account_groups(_("There are no account groups defined. Please de
 if (isset($_POST['_AccountList_update'])) 
 {
        $_POST['selected_account'] = $_POST['AccountList'];
+       unset($_POST['account_code']);
 }
 
 if (isset($_POST['selected_account']))
@@ -71,19 +72,22 @@ if (isset($_POST['add']) || isset($_POST['update']))
                        $_POST['account_code'] = strtoupper($_POST['account_code']);
        if ($selected_account) 
                {
-               update_gl_account($_POST['account_code'], $_POST['account_name'], 
-                               $_POST['account_type'], $_POST['account_code2']);
-                       update_record_status($_POST['account_code'], $_POST['inactive'],
-                               'chart_master', 'account_code');
-                       $Ajax->activate('account_code'); // in case of status change
-                       display_notification(_("Account data has been updated."));
+               if (update_gl_account($_POST['account_code'], $_POST['account_name'], 
+                               $_POST['account_type'], $_POST['account_code2'])) {
+                               update_record_status($_POST['account_code'], $_POST['inactive'],
+                                       'chart_master', 'account_code');
+                               $Ajax->activate('account_code'); // in case of status change
+                               display_notification(_("Account data has been updated."));
+                       }
                }
        else 
                {
-               add_gl_account($_POST['account_code'], $_POST['account_name'], 
-                               $_POST['account_type'], $_POST['account_code2']);
-                       $selected_account = $_POST['AccountList'] = $_POST['account_code'];
-                       display_notification(_("New account has been added."));
+               if (add_gl_account($_POST['account_code'], $_POST['account_name'], 
+                               $_POST['account_type'], $_POST['account_code2']))
+                               {
+                                       display_notification(_("New account has been added."));
+                                       $selected_account = $_POST['AccountList'] = $_POST['account_code'];
+                               }
                }
                $Ajax->activate('_page_body');
        }
@@ -209,8 +213,9 @@ if (isset($_POST['delete']))
        if (can_delete($selected_account))
        {
                delete_gl_account($selected_account);
-               $selected_account = $_POST['account_code'] = $_POST['AccountList'] = '';
+               $selected_account = $_POST['AccountList'] = '';
                display_notification(_("Selected account has been deleted"));
+               unset($_POST['account_code']);
                $Ajax->activate('_page_body');
        }
 } 
@@ -253,11 +258,13 @@ if ($selected_account != "")
                
        label_row(_("Account Code:"), $_POST['account_code']);
 } 
-else 
+else
 {
-       $_POST['account_code'] = $_POST['account_code2'] = '';
-       $_POST['account_name']  = $_POST['account_type'] = '';
-       $_POST['inactive'] = 0;
+       if (!isset($_POST['account_code'])) {
+               $_POST['account_code'] = $_POST['account_code2'] = '';
+               $_POST['account_name']  = $_POST['account_type'] = '';
+               $_POST['inactive'] = 0;
+       }
        text_row_ex(_("Account Code:"), 'account_code', 11);
 }