0000593,0001093: Prepayments made against orders implemented.
[fa-stable.git] / includes / ui / ui_lists.inc
index 14eb54436083283ba3f40cbaa5d4355ea2a499bc..5f7601497e2a9850a6b375c24800f4e6cd65b7d7 100644 (file)
@@ -417,6 +417,21 @@ function _format_add_curr($row)
                '' : (" - " . $row[2]));
 }
 
+function add_edit_combo($type)
+{
+       global $path_to_root, $popup_editors, $use_icon_for_editkey;
+
+       if (!isset($use_icon_for_editkey) || $use_icon_for_editkey==0)
+               return "";
+       // Derive theme path
+       $theme_path = $path_to_root . '/themes/' . user_theme();
+
+       $key = $popup_editors[$type][1];
+       $onclick = "onclick=\"javascript:callEditor($key); return false;\"";
+       $img = "<img width='12' height='12' border='0' alt='Add/Edit' title='Add/Edit' src='$theme_path/images/".ICON_EDIT."'>";
+       return "<a target = '_blank' href='#' $onclick tabindex='-1'>$img</a>"; 
+}
+
 function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false,
        $all=false, $editkey = false)
 {
@@ -428,8 +443,8 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_
 
        if ($editkey)
                set_editor('supplier', $name, $editkey);
-               
-       return combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
+
+       $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name',
        array(
                'format' => '_format_add_curr',
            'order' => array('supp_ref'),
@@ -443,6 +458,9 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_
                _('Select supplier'),
                'show_inactive'=>$all
                ));
+       if ($editkey)
+               $ret .= add_edit_combo('supplier');             
+       return $ret;
 }
 
 function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, 
@@ -477,7 +495,7 @@ function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_
        if ($editkey)
                set_editor('customer', $name, $editkey);
 
-       return combo_input($name, $selected_id, $sql, 'debtor_no', 'name',
+       $ret = combo_input($name, $selected_id, $sql, 'debtor_no', 'debtor_ref',
        array(
            'format' => '_format_add_curr',
            'order' => array('debtor_ref'),
@@ -492,6 +510,9 @@ function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_
                _('Select customer'),
                'show_inactive' => $show_inactive
        ) );
+       if ($editkey)
+               $ret .= add_edit_combo('customer');
+       return $ret;
 }
 
 function customer_list_cells($label, $name, $selected_id=null, $all_option=false, 
@@ -508,6 +529,7 @@ 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)
 {
+
        echo "<tr><td class='label'>$label</td><td nowrap>";
        echo customer_list($name, $selected_id, $all_option, $submit_on_change,
                $show_inactive, $editkey);
@@ -528,7 +550,7 @@ function customer_branches_list($customer_id, $name, $selected_id=null,
                set_editor('branch', $name, $editkey);
 
        $where = $enabled ? array("disable_trans = 0") : array();
-       return  combo_input($name, $selected_id, $sql, 'branch_code', 'br_name',
+       $ret = combo_input($name, $selected_id, $sql, 'branch_code', 'branch_ref',
        array(
                'where' => $where,
                'order' => array('branch_ref'),
@@ -537,6 +559,11 @@ function customer_branches_list($customer_id, $name, $selected_id=null,
                'select_submit'=> $submit_on_change,
                'sel_hint' => _('Select customer branch')
        ) );
+       if ($editkey)
+       {
+               $ret .= add_edit_combo('branch');
+       }
+       return $ret;
 }
 //------------------------------------------------------------------------------------------------
 
@@ -718,7 +745,7 @@ function stock_items_list($name, $selected_id=null, $all_option=false,
        if ($editkey)
                set_editor('item', $name, $editkey);
 
-       return combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
+       $ret = combo_input($name, $selected_id, $sql, 'stock_id', 's.description',
        array_merge(
          array(
                'format' => '_format_stock_items',
@@ -732,6 +759,9 @@ function stock_items_list($name, $selected_id=null, $all_option=false,
                'category' => 2,
                'order' => array('c.description','stock_id')
          ), $opts) );
+       if ($editkey)
+               $ret .= add_edit_combo('item');
+       return $ret;
 }
 
 function _format_stock_items($row)
@@ -1407,8 +1437,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;
@@ -1418,6 +1450,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
@@ -1450,14 +1484,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(
@@ -1467,13 +1503,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";
 }
@@ -2327,4 +2363,91 @@ function coa_list_row($label, $name, $value=null)
        echo array_selector( $name, $value, $coas );
        echo "</td></tr>\n";
 }
-?>
\ No newline at end of file
+
+function payment_services($name)
+{
+       global $payment_services;
+
+       $services = array_combine(array_keys($payment_services), array_keys($payment_services));
+
+       return array_selector($name, null, $services, array(
+                       'spec_option'=> _("No payment Link"),
+                       'spec_id' => '',
+               ));
+}
+
+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";
+}