Merged changes up to 2.3.16 into unstable
[fa-stable.git] / includes / ui / ui_lists.inc
index a3b5cf88e7ba7a0d273a754e4bcd7bbba3665445..f406d007aede01599ba0c0fcae489f064ff4d735 100644 (file)
@@ -443,7 +443,7 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_
 
        if ($editkey)
                set_editor('supplier', $name, $editkey);
-               
+
        $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
        array(
                'format' => '_format_add_curr',
@@ -529,7 +529,6 @@ function customer_list_cells($label, $name, $selected_id=null, $all_option=false
 function customer_list_row($label, $name, $selected_id=null, $all_option = false, 
        $submit_on_change=false, $show_inactive=false, $editkey = false)
 {
-       global $path_to_root;
 
        echo "<tr><td class='label'>$label</td><td nowrap>";
        echo customer_list($name, $selected_id, $all_option, $submit_on_change,
@@ -563,7 +562,7 @@ function customer_branches_list($customer_id, $name, $selected_id=null,
        if ($editkey)
        {
                $ret .= add_edit_combo('branch');
-       }       
+       }
        return $ret;
 }
 //------------------------------------------------------------------------------------------------
@@ -761,9 +760,8 @@ function stock_items_list($name, $selected_id=null, $all_option=false,
                'order' => array('c.description','stock_id')
          ), $opts) );
        if ($editkey)
-               $ret .= add_edit_combo('item');         
+               $ret .= add_edit_combo('item');
        return $ret;
-         
 }
 
 function _format_stock_items($row)
@@ -924,7 +922,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("mb_flag!= 'M'"), 
+               array('where'=>array("NOT no_purchase"), 
                        'show_inactive'=>$all), $editkey);
 }
 //
@@ -936,7 +934,7 @@ function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
        if ($label != null)
                echo "<td>$label</td>\n";
        echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
-               array('where'=>array("mb_flag!= 'M'"), 
+               array('where'=>array("NOT no_purchase"), 
                         'editable' => 30,
                         'cells'=>true), $editkey);
 }
@@ -1441,8 +1439,10 @@ function bank_accounts_list_row($label, $name, $selected_id=null, $submit_on_cha
 }
 //-----------------------------------------------------------------------------------------------
 
-function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
+function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
 {
+       global $all_items;
+
        $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
                FROM ".TB_PREF."bank_accounts
                WHERE ".TB_PREF."bank_accounts.account_type=".BT_CASH;
@@ -1452,6 +1452,8 @@ function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_cha
        echo "<td>";
        echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
        array(
+               'spec_option' => $all_option,
+               'spec_id' => $all_items,
                'format' => '_format_add_curr',
                'select_submit'=> $submit_on_change,
                'async' => true
@@ -1484,14 +1486,16 @@ function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $sub
 //-----------------------------------------------------------------------------------------------
 // Payment type selector for current user.
 //
-function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true)
+function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
 {
        $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms";
-       
+
        if ($category == PM_CASH) // only cash
                        $sql .= " WHERE days_before_due=0 AND day_in_following_month=0";
-       if ($category == PM_CREDIT) // only delayed payments
-                       $sql .= " WHERE days_before_due!=0 OR day_in_following_month!=0";
+       elseif ($category == PM_CREDIT) // only delayed payments
+                       $sql .= " WHERE days_before_due".($prepayments ? '!=': '>')."0 OR day_in_following_month!=0";
+       elseif (!$prepayments)
+                       $sql .= " WHERE days_before_due>=0";
 
        return combo_input($name, $selected_id, $sql, 'terms_indicator', 'terms',
        array(
@@ -1501,13 +1505,13 @@ function sale_payment_list($name, $category, $selected_id=null, $submit_on_chang
 
 }
 
-function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true)
+function sale_payment_list_cells($label, $name, $category, $selected_id=null, $submit_on_change=true, $prepayments=true)
 {
        if ($label != null)
                echo "<td class='label'>$label</td>\n";
        echo "<td>";
 
-       echo sale_payment_list($name, $category, $selected_id, $submit_on_change);
+       echo sale_payment_list($name, $category, $selected_id, $submit_on_change, $prepayments);
 
        echo "</td>\n";
 }
@@ -2367,4 +2371,78 @@ function payment_services($name)
                ));
 }
 
-?>
+function tax_algorithm_list($name, $value=null, $submit_on_change = false)
+{
+       global $tax_algorithms;
+       
+       return array_selector($name, $value, $tax_algorithms, 
+               array( 
+                       'select_submit'=> $submit_on_change,
+                       'async' => true,
+                       )
+       );
+}
+
+function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
+{
+       if ($label != null)
+               echo "<td>$label</td>\n";
+       echo "<td>";
+       echo tax_algorithm_list($name, $value, $submit_on_change);
+       echo "</td>\n";
+}
+
+function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
+{
+       echo "<tr><td class='label'>$label</td>";
+       tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
+       echo "</tr>\n";
+}
+//----------------------------------------------------------------------------------------------
+
+function subledger_list($name, $account, $selected_id=null)
+{
+       global $all_items;
+
+       $type = is_subledger_account($account);
+       if (!$type)
+               return '';
+
+       if($type > 0)
+               $sql = "SELECT DISTINCT d.debtor_no as id, debtor_ref as name 
+               FROM "
+               .TB_PREF."debtors_master d,"
+               .TB_PREF."cust_branch c
+               WHERE d.debtor_no=c.debtor_no AND c.receivables_account=".db_escape($account);
+       else
+               $sql = "SELECT supplier_id as id, supp_ref as name 
+               FROM "
+               .TB_PREF."suppliers s
+               WHERE s.payable_account=".db_escape($account);
+
+       $mode = get_company_pref('no_customer_list');
+
+       return combo_input($name, $selected_id, $sql, 'id', 'name',
+       array(
+               'type' => 1,
+               'size' => 20,
+               'async' => false,
+       ) );
+}
+
+function subledger_list_cells($label, $name, $account, $selected_id=null)
+{
+       if ($label != null)
+               echo "<td>$label</td>\n";
+       echo "<td nowrap>";
+       echo subledger_list($name, $account, $selected_id);
+       echo "</td>\n";
+}
+
+function subledger_list_row($label, $name, $selected_id=null, $all_option = false, 
+       $submit_on_change=false, $show_inactive=false, $editkey = false)
+{
+       echo "<tr><td class='label'>$label</td><td nowrap>";
+       echo subledger_list($name, $account, $selected_id);
+       echo "</td>\n</tr>\n";
+}