Budget Entry: ajax page reload on params change, added atomic functions for budget...
[fa-stable.git] / includes / ui / ui_lists.inc
index c7c5a4061bb80b2449fa96886a35a1c7faf27402..b803ac3215b40c4f9231d2ab5742c5e96983b142 100644 (file)
@@ -365,7 +365,7 @@ $opts = array(              // default options
                $selector .= ' '.$opts['editlink'];
 
        if ($search_box && $opts['cells'])
-               $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td>$selector$img</td>";
+               $str = ($edit_entry!='' ? "<td>$edit_entry</td>" : '')."<td nowrap>$selector$img</td>";
        else
                $str = $edit_entry.$selector.$img;
        return $str;
@@ -761,19 +761,19 @@ function _format_fiscalyears($row)
        . "&nbsp;&nbsp;" . ($row[3] ? _('Closed') : _('Active'));
 }
 
-function fiscalyears_list_cells($label, $name, $selected_id=null)
+function fiscalyears_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
 {
        if ($label != null)
                echo "<td>$label</td>\n";
        echo "<td>";
-       echo fiscalyears_list($name, $selected_id);
+       echo fiscalyears_list($name, $selected_id, $submit_on_change);
        echo "</td>\n";
 }
 
-function fiscalyears_list_row($label, $name, $selected_id=null)
+function fiscalyears_list_row($label, $name, $selected_id=null, $submit_on_change=false)
 {
        echo "<tr><td class='label'>$label</td>";
-       fiscalyears_list_cells(null, $name, $selected_id);
+       fiscalyears_list_cells(null, $name, $selected_id, $submit_on_change);
        echo "</tr>\n";
 }
 //------------------------------------------------------------------------------------
@@ -823,13 +823,17 @@ function dimensions_list_row($label, $name, $selected_id=null, $no_option=false,
 function stock_items_list($name, $selected_id=null, $all_option=false, 
        $submit_on_change=false, $opts=array(), $editkey = false, $type = "stock")
 {
-       $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
-                       FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
+       $sql = "SELECT stock_id, s.description, c.description, shipper.shipper_name, s.inactive, s.editable
+                       FROM ".TB_PREF."stock_master s 
+                               LEFT JOIN ".TB_PREF."shippers shipper ON shipper.shipper_id=s.shipper_id
+                               LEFT JOIN ".TB_PREF."stock_category c ON s.category_id=c.category_id";
 
-       if (isset($opts['fixed_asset']) && $opts['fixed_asset'])
-               $sql .= " AND mb_flag='F'";
+       if (isset($opts['shipping']) && $opts['shipping'])
+               $where[] = "mb_flag='T'";
+       elseif (isset($opts['fixed_asset']) && $opts['fixed_asset'])
+               $where[] = "mb_flag='F'";
        else
-               $sql .= " AND mb_flag!='F'";
+               $where[] = "NOT mb_flag IN('F','T')";
 
        if ($editkey)
                set_editor('item', $name, $editkey);
@@ -842,14 +846,15 @@ function stock_items_list($name, $selected_id=null, $all_option=false,
                        'spec_id' => ALL_TEXT,
                        'search_box' => true,
                        'search' => array("stock_id", "c.description","s.description"),
-                       'search_submit' => get_company_pref('no_item_list')!=0 && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']),
+                       'search_submit' => get_company_pref('no_item_list') != 0 && (!isset($opts['fixed_asset']) || !$opts['fixed_asset']),
                        'size'=>10,
                        'select_submit'=> $submit_on_change,
                        'category' => 2,
-                       'order' => array('c.description','stock_id'),
+                       'order' => (isset($opts['shipping']) && $opts['shipping']) ? array('shipper.shipper_name','stock_id'): array('c.description','stock_id'),
                        'editlink' => $editkey ? add_edit_combo('item') : false,
                        'editable' => false,
-                       'max' => 255
+                       'max' => 255,
+                       'where' => $where
                  ), $opts), $type );
        return $ret;
 }
@@ -907,7 +912,7 @@ function sales_items_list($name, $selected_id=null, $all_option=false,
                        ".TB_PREF."stock_category c
                        ON i.category_id=c.category_id
                        WHERE i.stock_id=s.stock_id
-      AND mb_flag != 'F'";
+      AND NOT mb_flag IN('F','T')";
 
        
        if ($type == 'local')   { // exclude foreign codes
@@ -944,7 +949,7 @@ function sales_items_list_cells($label, $name, $selected_id=null, $all_option=fa
        if ($label != null)
                echo "<td>$label</td>\n";
        echo sales_items_list($name, $selected_id, $all_option, $submit_on_change,
-               '', array('cells'=>true));
+               '', array('cells'=>true, 'max'=>50)); // maximum is set to 50 and not default 255.
 }
 
 function sales_kits_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
@@ -1032,7 +1037,7 @@ function stock_purchasable_items_list($name, $selected_id=null,
        $all_option=false, $submit_on_change=false, $all=false, $editkey=false)
 {
        return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
-               array('where'=>array("NOT no_purchase"), 
+               array('where'=>array("NOT no_purchase", "mb_flag!='F'"), 
                        'show_inactive'=>$all), $editkey, "stock_purchased");
 }
 //
@@ -1051,19 +1056,53 @@ function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
 
 //------------------------------------------------------------------------------------
 
-function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
+function shipping_methods_list($name, $selected_id=null, $all_option=false, $submit_on_change=false)
+{
+       return stock_items_list($name, $selected_id, $all_option, $submit_on_change,
+               array('type'=>1, 'shipping'=>true, 'category' => false, 'search_box'=>false, 'search_sumbit' => false),
+                       false, false);//, "shipping_methods");
+}
+
+function shipping_methods_list_cells($label, $name, $selected_id=null,
+                               $all_option=false, $submit_on_change=false)
+{
+       if ($label != null)
+               echo "<td>$label</td>\n";
+       echo "<td>";
+       echo shipping_methods_list($name, $selected_id, $all_option, $submit_on_change);
+       echo "</td>\n";
+}
+
+function shipping_methods_list_row($label, $name, $selected_id=null,
+               $all_option=false, $submit_on_change=false)
+{
+       echo "<tr><td class='label'>$label</td>";
+       shipping_methods_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
+       echo "</tr>\n";
+}
+
+//------------------------------------------------------------------------------------
+
+function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true, $all=true)
 {
        global $stock_types;
 
+       $options = $stock_types;
+       if (!$all)
+       {
+               unset($options['T']);
+               unset($options['F']);
+       }
        echo "<tr>";
        if ($label != null)
                echo "<td class='label'>$label</td>\n";
        echo "<td>";
-
-       echo array_selector($name, $selected_id, $stock_types, 
+               
+       echo array_selector($name, $selected_id, $options, 
                array( 
                        'select_submit'=> true, 
-                       'disabled' => !$enabled) );
+                       'disabled' => !$enabled)
+               );
        echo "</td></tr>\n";
 }
 
@@ -1152,11 +1191,12 @@ function stock_depreciable_fa_list_cells($label, $name, $selected_id=null,
        ( SELECT stock_id FROM ".TB_PREF."stock_moves WHERE (type=".ST_CUSTDELIVERY." OR type=".ST_INVADJUST.") AND qty!=0 )";
 
        $year = get_current_fiscalyear();
-       $y = date('Y', strtotime($year['end']));
+       $begin = date2sql(add_months(sql2date($year['begin']), -1));
+       $end = date2sql(add_months(sql2date($year['end']), -1));
 
        // check if current fiscal year
-       $where_opts[] = "depreciation_date < '".$y."-12-01'";
-       $where_opts[] = "depreciation_date >= '".($y-1)."-12-01'";
+       $where_opts[] = "depreciation_date <= '".$end."'";
+       $where_opts[] = "depreciation_date >= '".$begin."'";
 
        $where_opts[] = "material_cost > 0";
        $where_opts[] = "mb_flag='F'";
@@ -1262,26 +1302,31 @@ function item_tax_types_list_row($label, $name, $selected_id=null, $show_inactiv
 
 //------------------------------------------------------------------------------------
 
-function shippers_list($name, $selected_id=null)
+function shippers_list($name, $selected_id=null, $none_option=false, $submit_on_change=false)
 {
        $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers";
        return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', 
-               array('order'=>array('shipper_name')));
+               array('order'=>array('shipper_name'),
+                       'spec_option' => $none_option,
+                       'spec_id' => ALL_NUMERIC,
+                       'select_submit'=> $submit_on_change,
+                       'async' => false,
+));
 }
 
-function shippers_list_cells($label, $name, $selected_id=null)
+function shippers_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
 {
        if ($label != null)
                echo "<td>$label</td>\n";
        echo "<td>";
-       echo shippers_list($name, $selected_id);
+       echo shippers_list($name, $selected_id, $none_option, $submit_on_change);
        echo "</td>\n";
 }
 
-function shippers_list_row($label, $name, $selected_id=null)
+function shippers_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
 {
        echo "<tr><td class='label'>$label</td>";
-       shippers_list_cells(null, $name, $selected_id);
+       shippers_list_cells(null, $name, $selected_id, $none_option, $submit_on_change);
        echo "</tr>\n";
 }
 
@@ -1710,13 +1755,13 @@ function class_list_row($label, $name, $selected_id=null, $submit_on_change=fals
 }
 
 //-----------------------------------------------------------------------------------------------
-function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
+function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $type=false)
 {
        $where_opts = array();
-       if ($fixed_asset)
-               $where_opts[0] = "dflt_mb_flag='F'";
+       if (in_array($type, array('F', 'T')))
+               $where_opts[] = "dflt_mb_flag=".db_escape($type);
        else
-               $where_opts[0] = "dflt_mb_flag!='F'";
+               $where_opts[] = "NOT dflt_mb_flag IN('F','T')";
 
        $sql = "SELECT category_id, description, inactive FROM ".TB_PREF."stock_category";
        return combo_input($name, $selected_id, $sql, 'category_id', 'description',
@@ -1729,19 +1774,19 @@ function stock_categories_list($name, $selected_id=null, $spec_opt=false, $submi
                ));
 }
 
-function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
+function stock_categories_list_cells($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $type=false)
 {
        if ($label != null)
                echo "<td>$label</td>\n";
        echo "<td>";
-       echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
+       echo stock_categories_list($name, $selected_id, $spec_opt, $submit_on_change, $type);
        echo "</td>\n";
 }
 
-function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $fixed_asset=false)
+function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=false, $submit_on_change=false, $type=false)
 {
        echo "<tr><td class='label'>$label</td>";
-       stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $fixed_asset);
+       stock_categories_list_cells(null, $name, $selected_id, $spec_opt, $submit_on_change, $type);
        echo "</tr>\n";
 }
 
@@ -1862,11 +1907,11 @@ function gl_all_accounts_list_cells($label, $name, $selected_id=null,
 }
 
 function gl_all_accounts_list_row($label, $name, $selected_id=null, 
-       $skip_bank_accounts=false, $cells=false, $all_option=false, $type_id=false)
+       $skip_bank_accounts=false, $cells=false, $all_option=false, $submit_on_change=false, $all=false, $type_id=false)
 {
        echo "<tr><td class='label'>$label</td>";
        gl_all_accounts_list_cells(null, $name, $selected_id, 
-               $skip_bank_accounts, $cells, $all_option, $type_id);
+               $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all, $type_id);
        echo "</tr>\n";
 }
 
@@ -2567,6 +2612,26 @@ function payment_services($name)
                ));
 }
 
+function vat_category_list_row($label, $name, $selected_id=null, $enabled = true, $submit_on_change=false, $show_obsolete=false)
+{
+       global $vat_categories;
+
+       echo "<tr>";
+       if ($label != null)
+               echo "<td class='label'>$label</td>\n";
+       echo "<td>";
+        
+       $categories = $vat_categories;
+       if (!$show_obsolete)
+         unset($categories[VC_MEDIA]); // obsolete category removed to avoid mistake usage
+
+       echo array_selector($name, $selected_id, $categories,
+               array( 'select_submit'=> $submit_on_change, 
+                       'disabled' => !$enabled));
+       echo "</td></tr>\n";
+
+}
+
 function tax_algorithm_list($name, $value=null, $submit_on_change = false)
 {
        global $tax_algorithms;
@@ -2690,7 +2755,7 @@ function accounts_type_list_row($label, $name, $selected_id=null)
 function users_list_cells($label, $name, $selected_id=null, $submit_on_change=false, $spec_opt=true)
 {
     $where = false;
-    $sql = " SELECT user_id, real_name FROM ".TB_PREF."users";
+       $sql = " SELECT user_id, IF(real_name = '', user_id, real_name) FROM ".TB_PREF."users";
 
     if ($label != null)
         echo "<td>$label</td>\n";
@@ -2721,3 +2786,20 @@ function collations_list_row($label, $name, $selected_id=null)
                array('select_submit'=> false) );
        echo "</td></tr>\n";
 }
+
+function vat_areas_list_row($label, $name, $selected_id=null, $enabled=true)
+{
+       global $tax_area_types;
+
+       echo "<tr>";
+       if ($label != null)
+               echo "<td class='label'>$label</td>\n";
+       echo "<td>";
+
+       echo array_selector($name, $selected_id, $tax_area_types,
+               array(
+                       'select_submit'=> true,
+                       'disabled' => !$enabled) );
+       echo "</td></tr>\n";
+}
+