SOLVED - Master/Detail copy sequence
[QUOTE=kafecadm;34146]Hey Dan:
Remember you should use it like
if ( sc_btn_copy() )
{
//your code here
}
[/QUOTE]
Hello,
I solved the problem, thanks for the hint.
Here is how you can copy the slave fields for a copied master:
example:
there are necessaire 3 table:
>
'file' - master table ();
..>>> operation fields ..>>> id, type, path, file_label, file_name, file_description, file_number, order_nr, order_name, part_name, drawing_nr, drawing_v, stipulated_total, achieved_total, info, duplicate, assembly_picture, scanned_file, add, update_ti, user, update_us
'operation' - slave table;
..>>> operation fields ..>>> id, type, file_id, file_number, order_name, part_name, drawing_nr, file_name, order_nr, operation, parts_cod, cost_group_id, cost_center, wi_cod, sdv, stipulated, achieved, worker_name, checker, diference, add, update_ti, user, update_us
'operations_tmp' - table needed to put the information that you whant to copy.
..>>> operations_tmp fields ..>>> id, type, file_id, file_number, order_name, part_name, drawing_nr, file_name, order_nr, operation, parts_cod, cost_group_id, cost_center, wi_cod, sdv, stipulated, achieved, worker_name, checker, diference, add, update_ti, user, update_us
in the master table form (file) you must creat 2 php methods:
>
1) copy_db_before_insert;
2) copy_db_after_insert.
In the first php method “copy_db_before_insert”:
>
if (sc_btn_copy)
{
// copy records in operations_tmp
$check_sql = 'INSERT INTO operations_tmp'
. ' SELECT *'
. ' FROM operation '
. " WHERE file_id = '" . {id} . "'";
sc_select(rs, $check_sql);
}
- Copy in the second php method “copy_db_after_insert”:
>
// update records with the new values in operations_tmp
$update_table = 'operations_tmp'; // Table name
$update_fields = array( // Field list, add as many as needed
"file_id = '{id}'",
"type = '{type}'",
"file_name = '{file_name}'",
"file_number = '{file_number}'",
"order_nr = '{order_nr}'",
"order_name = '{order_name}'",
"part_name = '{part_name}'",
"drawing_nr = '{drawing_nr}'",
);
$update_sql = 'UPDATE ' . $update_table
. ' SET ' . implode(', ', $update_fields);
sc_exec_sql($update_sql);
// copy records in operation
$check_sql = 'INSERT INTO operation (type, file_id, file_number, order_name, part_name, drawing_nr, file_name, order_nr, operation, parts_cod, cost_group_id, cost_center, wi_cod, sdv, stipulated, achieved, worker_name, checker, diference)'
. ' SELECT type, file_id, file_number, order_name, part_name, drawing_nr, file_name, order_nr, operation, parts_cod, cost_group_id, cost_center, wi_cod, sdv, stipulated, achieved, worker_name, checker, diference '
. ' FROM operations_tmp '
. " WHERE file_id = '" . {id} . "'";
sc_select(rs, $check_sql);
// delete all records in operations_tmp
$empty_sql = 'truncate operations_tmp';
sc_exec_sql($empty_sql);
After that write “copy_db_before_insert();” in the:
>
- onAplicationInit;
- onNavigate;
- onScriptInit.
And after that write “copy_db_after_insert();” in the:
>
- onAfterInsert.
After that create an dependence and link the id of the master table with file_id of the slave table (select both int)- in the form of the master table.
Done. Have fun.