If setting the delivered items in PO Receive Items to 0 the value is not updated
[fa-stable.git] / inventory / manage / items.php
index c841514c599fa8a0d1c05ed379b88bbc61d3f402..112e1b2cd22eed2f26c37268dd2c7d0374e927ed 100644 (file)
@@ -29,20 +29,23 @@ if (isset($_GET['stock_id']))
 {
        $_POST['stock_id'] = $stock_id = $_GET['stock_id'];
 }
-else if (isset($_POST['stock_id']))
+elseif (isset($_POST['stock_id']))
 {
        $stock_id = $_POST['stock_id'];
 }
-
 if (list_updated('stock_id')) {
        $_POST['NewStockID'] = get_post('stock_id');
     clear_data();
        $Ajax->activate('details');
        $Ajax->activate('controls');
 }
+if (list_updated('category_id') || list_updated('mb_flag')) {
+       $Ajax->activate('details');
+}
 $upload_file = "";
 if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '') 
 {
+       $stock_id = $_POST['NewStockID'];
        $result = $_FILES['pic']['error'];
        $upload_file = 'Yes'; //Assume all is well to start off with
        $filename = $comp_path . "/$user_comp/images";
@@ -142,7 +145,13 @@ if (isset($_POST['addupdate']))
        
        if ($input_error != 1)
        {
-
+               if (check_value('del_image'))
+               {
+                       $filename = $comp_path . "/$user_comp/images/".item_img_name($_POST['NewStockID']).".jpg";
+                       if (file_exists($filename))
+                               unlink($filename);
+               }
+               
                if (!$new_item) 
                { /*so its an existing one */
 
@@ -164,8 +173,8 @@ if (isset($_POST['addupdate']))
                                $_POST['adjustment_account'], $_POST['assembly_account'], 
                                $_POST['dimension_id'], $_POST['dimension2_id']);
 
-               display_notification(_("A new item has been added."));
-               $_POST['stock_id'] = $_POST['NewStockID'];
+                       display_notification(_("A new item has been added."));
+                       $_POST['stock_id'] = $_POST['NewStockID'];
                }
                set_focus('stock_id');
                $Ajax->activate('_page_body');
@@ -291,7 +300,7 @@ if ($new_item)
        $company_record = get_company_prefs();
 
     if (!isset($_POST['inventory_account']) || $_POST['inventory_account'] == "")
-       $_POST['inventory_account'] = $company_record["default_inventory_act"];
+               $_POST['inventory_account'] = $company_record["default_inventory_act"];
 
     if (!isset($_POST['cogs_account']) || $_POST['cogs_account'] == "")
        $_POST['cogs_account'] = $company_record["default_cogs_act"];
@@ -305,6 +314,8 @@ if ($new_item)
        if (!isset($_POST['assembly_account']) || $_POST['assembly_account'] == "")
                $_POST['assembly_account'] = $company_record["default_assembly_act"];
 
+       if (list_updated('mb_flag') && is_service($_POST['mb_flag']))
+               $_POST['inventory_account'] = $company_record["default_cogs_act"];
 } 
 else 
 { // Must be modifying an existing item
@@ -326,7 +337,7 @@ else
                $_POST['assembly_account']      = $myrow['assembly_account'];
                $_POST['dimension_id']  = $myrow['dimension_id'];
                $_POST['dimension2_id'] = $myrow['dimension2_id'];
-       
+               $_POST['del_image'] = 0;        
                label_row(_("Item Code:"),$_POST['NewStockID']);
                hidden('NewStockID', $_POST['NewStockID']);
                set_focus('description');
@@ -366,15 +377,15 @@ table_section_title(_("GL Accounts"));
 
 gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']);
 
-gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']);
-
 if (!is_service($_POST['mb_flag'])) 
 {
+       gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']);
        gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
        gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']);
 }
 else 
 {
+       gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'inventory_account', $_POST['inventory_account']);
        hidden('cogs_account', $_POST['cogs_account']);
        hidden('adjustment_account', $_POST['adjustment_account']);
 }
@@ -391,13 +402,15 @@ table_section_title(_("Picture"));
 label_row(_("Image File (.jpg)") . ":", "<input type='file' id='pic' name='pic'>");
 // Add Image upload for New Item  - by Joe
 $stock_img_link = "";
+$check_remove_image = false;
 if (isset($_POST['NewStockID']) && file_exists("$comp_path/$user_comp/images/"
        .item_img_name($_POST['NewStockID']).".jpg")) 
 {
  // 31/08/08 - rand() call is necessary here to avoid caching problems. Thanks to Peter D.
        $stock_img_link .= "<img id='item_img' alt = '[".$_POST['NewStockID'].".jpg".
                "]' src='$comp_path/$user_comp/images/".item_img_name($_POST['NewStockID']).".jpg?nocache=".rand()."'".
-               " width='$pic_width' height='$pic_height' border='0'>";
+               " height='$pic_height' border='0'>";
+       $check_remove_image = true;     
 } 
 else 
 {
@@ -405,7 +418,9 @@ else
 }
 
 label_row("&nbsp;", $stock_img_link);
-
+if ($check_remove_image)
+       check_row(_("Delete Image:"), 'del_image', $_POST['del_image']);
+       
 end_outer_table(1);
 div_end();
 div_start('controls');