Topic: Salesman per sales group

Hello,

I've been desperate with ajax in Frontaccounting, but my question in another thread is not answered. I don't know if there is no one who understand or no one whol willing to share their knowledge. Anyway, I'm just try to ask agan. I hope someone will give some of their knowledge or I must find another application that easier to modified.

What I want to modify is basically simple. I want to create some dropdown which has another dropdown as the parent. It's exactly like customer and branch dropdown in sales order entry. I want to create this with sales group and salesman. I already modified that a salesman has only one sales group. In customer branch, I want to add this dropdown function. I have already modified the UI for displaying the dropdown in sales group so that it has submit on change. I saw another example that use Ajax->activate. But nothing happen. I don't know what I must do because there is no clue and I cannot debug with my code inspector because the post in header is very difficult to understand. Anyone can help?

Re: Salesman per sales group

There is no manual on how to use the ajax in FA.

To make it simple please have a look in /sales/includes/ui/sales_order_ui.inc

Look up the function display_order_header, line 258.

First in the function the $Ajax is defined as global.

$Ajax->update($name) can be used either for a single Control (the Control name) or a span of code with div_start($name) and div_end(), where you can declare your own name and use it in $Ajax->update.

Everytime the $Ajax->update is called the specific Control/code is called.

By looking at the code here, I guess you will get a first hint of how to use it.

/Joe

Re: Salesman per sales group

joe wrote:

There is no manual on how to use the ajax in FA.

To make it simple please have a look in /sales/includes/ui/sales_order_ui.inc

Look up the function display_order_header, line 258.

First in the function the $Ajax is defined as global.

$Ajax->update($name) can be used either for a single Control (the Control name) or a span of code with div_start($name) and div_end(), where you can declare your own name and use it in $Ajax->update.

Everytime the $Ajax->update is called the specific Control/code is called.

By looking at the code here, I guess you will get a first hint of how to use it.

/Joe



Thank you for your answer. I think this is the code :

       customer_list_row(_("Customer:"), 'customer_id', null, false, true, false, true);

        if ($order->customer_id != get_post('customer_id', -1)) {
            // customer has changed
            $Ajax->activate('branch_id');
        }
        customer_branches_list_row(_("Branch:"), $_POST['customer_id'], 'branch_id', null, false, true, true, true);


I don't know why, but, if I delete the if part, it still working. The code below still works like the code above. Do you know why?
       customer_list_row(_("Customer:"), 'customer_id', null, false, true, false, true);
       customer_branches_list_row(_("Branch:"), $_POST['customer_id'], 'branch_id', null, false, true, true, true);


And by the way, I already successfully created my modification of salesman per sales group. The issue is not the ajax, but the if part that trigger the ajax event.

Re: Salesman per sales group

By the way, why FA don't use jquery for ajax? I think it's easier and JsHttpRequest is already old (was made in2006, http://en.dklab.ru/lib/JsHttpRequest/).

Re: Salesman per sales group

Probably because FA developers prefer to spend their time to add new features to FA (or fix bug or answer question on the forum)  instead of fixing something which is not broken ... And if they were, they'll probably start by something else ;-)

/Elax

Re: Salesman per sales group

elax wrote:

Probably because FA developers prefer to spend their time to add new features to FA (or fix bug or answer question on the forum)  instead of fixing something which is not broken ... And if they were, they'll probably start by something else ;-)

/Elax

You are right. It's better to focus on fixing the bug. By the way I want to ask abou ajax again. Honsetly, the previous code is working but I don't know how it's working. When I tried to implement it in another page, it's not working. basically, I just want to do some simple change like in sales order UI. I want to create selector for customer, selector branch, info about currency, and info about sales group. When I change customer, the branch and currency is changed according the customer even though I don't add another code at all and I've been wondering why this code works. But, when I want to change the sales group according to branch, it's not working and I still have no idea why. So, i just want to ask a very simple and below is my code:

customer_list_row(_("Customer:"), 'customer_id', null, false, true, false, true);
customer_branches_list_row(_("Branch").':', $_POST['customer_id'], 'branch_id', null, false, true, true, true);
label_row(_("Currency:"), get_customer_currency($_POST['customer_id']));
amount_row(_("Project Value").':', 'value');
$branch = get_cust_branch($_POST['customer_id'], $_POST['branch_id']);
label_row(_("Business unit:"), get_sales_group_name($branch['group_no']));

When I read the sales order ui header function, I understand the flow of the logic. But I don't know which part is affecting the change because it's so may if there. So, from code above, can you help me to explain why customer branch and currency changed when I change customer but sales group name won't change even though I change branch? I really than you if you could help me with this. The code or customer and branch is copied form sales order ui.

Here is my full code:

<?php

$path_to_root = "../..";
$page_security = 'SA_SALESPROJECTS';

include_once($path_to_root . "/includes/session.inc");
$js = '';
$js .= get_js_date_picker();
page(_($help_context = "Sales Projects"), false, false, "", $js);
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/sales/includes/db/sales_projects_db.inc");

simple_page_mode(true);

function can_process() {
    if (strlen($_POST['project_name']) == 0) {
        display_error(_("Project name can not be empty."));
        set_focus('project_name');
        return false;
    }

    if (strlen($_POST['contract_no']) == 0) {
        display_error(_("Contract number can not be empty."));
        set_focus('contract_no');
        return false;
    }
    return true;
}

if ($Mode == 'ADD_ITEM' && can_process()) {
    
}

if ($Mode == 'UPDATE_ITEM' && can_process()) {
    
}

if ($Mode == 'Delete') {
    
}

if ($Mode == 'RESET') {
    
}

$result = get_all_projects(check_value('show_inactive'));

start_form();
start_table(TABLESTYLE, "width=80%");

$th = array(_('Project No'), _('Project Name'), _('Contract No'), _('Customer'), _('Branch'), _('Value'), _('Type'), '', '');
inactive_control_column($th);
table_header($th);
$k = 0;
while ($myrow = db_fetch($result)) {
    alt_table_row_color($k);
    label_cell($myrow["project_no"]);
    label_cell($myrow["project_name"]);
    label_cell($myrow["contract_no"]);
    label_cell($myrow["name"]);
    label_cell($myrow["br_name"]);
    label_cell($myrow["value"]);
    label_cell($myrow["project_type"]);
    inactive_control_cell($myrow["project_no"], $myrow["inactive"], 'sales_projects', 'project_no');
    edit_button_cell("Edit" . $myrow['project_no'], _("Edit"));
    delete_button_cell("Delete" . $myrow['project_no'], _("Delete"));
    end_row();
}
inactive_control_row($th);
end_table();

br();

start_table(TABLESTYLE2);

if ($selected_id != -1) {

    if ($Mode == 'Edit') {
        $comments = $_POST['comments'];
    }
    hidden('selected_id', $selected_id);
} else {
    $comments = '';
}

text_row_ex(_("Project Name") . ':', 'project_name', 25);
text_row_ex(_("Contract No") . ':', 'contract_no', 25);
customer_list_row(_("Customer:"), 'customer_id', null, false, true, false, true);
customer_branches_list_row(_("Branch").':', $_POST['customer_id'], 'branch_id', null, false, true, true, true);
label_row(_("Currency:"), get_customer_currency($_POST['customer_id']));
amount_row(_("Project Value").':', 'value');
$branch = get_cust_branch($_POST['customer_id'], $_POST['branch_id']);
label_row(_("Business unit:"), get_sales_group_name($branch['group_no']));
project_type_row(_("Project Type").':','project_type');
date_row(_("Start").':', 'start_date');
date_row(_("End").':', 'end_date');
project_ref_row(_("Project Ref").':','ref_project');
textarea_row(_("Comments") . ':', 'comments',$comments, 25,3);
end_table(1);

submit_add_or_update_center($selected_id == -1, '', 'both');

end_form();
end_page();
?>