Cleanup: removed all closing tags in php files.
[fa-stable.git] / inventory / manage / sales_kits.php
index 245656ce938f61400d2d8e7cff37e96c76b19c4f..1ccc53162aaff818e9a1751c46ac7db93e7fde2d 100644 (file)
@@ -1,10 +1,19 @@
 <?php
-
-$page_security = 11;
-$path_to_root="../..";
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       as published by the Free Software Foundation, either version 3 
+       of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
+$page_security = 'SA_SALESKIT';
+$path_to_root = "../..";
 include_once($path_to_root . "/includes/session.inc");
 
-page(_("Sales Kits & Alias Codes"));
+page(_($help_context = "Sales Kits & Alias Codes"));
 
 include_once($path_to_root . "/includes/date_functions.inc");
 include_once($path_to_root . "/includes/ui.inc");
@@ -25,11 +34,9 @@ if (isset($_GET['item_code']))
 //--------------------------------------------------------------------------------------------------
 function display_kit_items($selected_kit)
 {
-       global $table_style;
-
        $result = get_item_kit($selected_kit);
-div_start('bom');
-       start_table("$table_style width=60%");
+       div_start('bom');
+       start_table(TABLESTYLE, "width=60%");
        $th = array(_("Stock Item"), _("Description"), _("Quantity"), _("Units"),
                '','');
        table_header($th);
@@ -46,7 +53,7 @@ div_start('bom');
                        $myrow["units"] == '' ? 0 : get_qty_dec($myrow["comp_name"]));
         label_cell($myrow["units"] == '' ? _('kit') : $myrow["units"]);
                edit_button_cell("Edit".$myrow['id'], _("Edit"));
-               edit_button_cell("Delete".$myrow['id'], _("Delete"));
+               delete_button_cell("Delete".$myrow['id'], _("Delete"));
         end_row();
 
        } //END WHILE LIST LOOP
@@ -75,7 +82,7 @@ function update_component($kit_code, $selected_item)
        elseif ($selected_item == -1)   // adding new item or new alias/kit
        {
                if (get_post('item_code') == '') { // New kit/alias definition
-                       $kit = get_item_kit($_POST['item_code']);
+                       $kit = get_item_kit($_POST['kit_code']);
                if (db_num_rows($kit)) {
                                $input_error = 1;
                        display_error( _("This item code is already assigned to stock item or sale kit."));
@@ -143,7 +150,10 @@ if ($Mode == 'Delete')
        // 
        $other_kits = get_where_used($_POST['item_code']);
        $num_kits = db_num_rows($other_kits);
-       if ($num_kits) {
+
+       $kit = get_item_kit($_POST['item_code']);
+       if ((db_num_rows($kit) == 1) && $num_kits) {
+
                $msg = _("This item cannot be deleted because it is the last item in the kit used by following kits")
                        .':<br>';
 
@@ -166,17 +176,16 @@ if ($Mode == 'RESET')
        unset($_POST['quantity']);
        unset($_POST['component']);
 }
-
 //--------------------------------------------------------------------------------------------------
 
-start_form(false, true);
+start_form();
 
 echo "<center>" . _("Select a sale kit:") . "&nbsp;";
-sales_kits_list('item_code', null, _('New kit'), true);
+echo sales_kits_list('item_code', null, _('New kit'), true);
 echo "</center><br>";
 $props = get_kit_props($_POST['item_code']);
 
-if (isset($_POST['_item_code_update'])) {
+if (list_updated('item_code')) {
        if (get_post('item_code') == '')
                $_POST['description'] = '';
        $Ajax->activate('_page_body');
@@ -186,13 +195,14 @@ $selected_kit = $_POST['item_code'];
 //----------------------------------------------------------------------------------
 if (get_post('item_code') == '') {
 // New sales kit entry
-       start_table($table_style2);
+       start_table(TABLESTYLE2);
        text_row(_("Alias/kit code:"), 'kit_code', null, 20, 21);
 } else
-{ // Kit selected so display bom or edit component
+{
+        // Kit selected so display bom or edit component
        $_POST['description'] = $props['description'];
        $_POST['category'] = $props['category_id'];
-       start_table($table_style2);
+       start_table(TABLESTYLE2);
        text_row(_("Description:"), 'description', null, 50, 200);
        stock_categories_list_row(_("Category:"), 'category', null);
        submit_row('update_name', _("Update"), false, 'align=center colspan=2', _('Update kit/alias name'), true);
@@ -200,7 +210,7 @@ if (get_post('item_code') == '') {
        end_table(1);
        display_kit_items($selected_kit);
        echo '<br>';
-       start_table($table_style2);
+       start_table(TABLESTYLE2);
 }
 
        if ($Mode == 'Edit') {
@@ -215,8 +225,10 @@ if (get_post('item_code') == '') {
 //     if (get_post('description') == '')
 //             $_POST['description'] = get_kit_name($_POST['component']);
        if (get_post('item_code') == '') { // new kit/alias
-               $_POST['description'] = $props['description'];
-               $_POST['category'] = $props['category_id'];
+               if ($Mode!='ADD_ITEM' && $Mode!='UPDATE_ITEM') {
+                       $_POST['description'] = $props['description'];
+                       $_POST['category'] = $props['category_id'];
+               }
                text_row(_("Description:"), 'description', null, 50, 200);
                stock_categories_list_row(_("Category:"), 'category', null);
        }
@@ -229,13 +241,13 @@ if (get_post('item_code') == '') {
                $Ajax->activate('quantity');
                $Ajax->activate('category');
        }
-       qty_row(_("Quantity:"), 'quantity', null, '', $units, $dec);
+       
+       qty_row(_("Quantity:"), 'quantity', number_format2(1, $dec), '', $units, $dec);
 
        end_table(1);
-       submit_add_or_update_center($selected_id == -1, '', true);
+       submit_add_or_update_center($selected_id == -1, '', 'both');
        end_form();
 //----------------------------------------------------------------------------------
 
 end_page();
 
-?>