Your second option is fine I feel. Because sometimes. People may make reverse entries once they made mistake in another form. So I think the warning would be fine. At the same time even if they post it with warning. It should work and submit the journal entry.
Here is a screenshot for reference what i talked. And code i modified in gl_journal.php
// New function to check it
function check_account_selection($code, $amount){
$sql = "SELECT ms.*, cl.class_name, cl.ctype FROM ".TB_PREF."chart_master AS ms LEFT JOIN ".TB_PREF."chart_types AS tp ON ms.account_type= tp.id LEFT JOIN ".TB_PREF."chart_class AS cl ON cl.cid = tp.class_id WHERE account_code= ".db_escape($code);
$res = db_query($sql, "Cant get the chart class selection");
if(db_num_rows($res) == 1 ){
if($row = db_fetch($res)){
if($row['ctype'] == CL_EXPENSE && $amount > 0)
display_warning(_("You are entered the Expense under the debit side"));
if($row['ctype'] == CL_ASSETS && $amount < 0 )
display_warning(_("You are entered the Asset in credit side"));
}
}
}
function handle_new_item()
{
if (!check_item_data())
return;
if (input_num('AmountDebit') > 0)
$amount = input_num('AmountDebit');
else
$amount = -input_num('AmountCredit');
check_account_selection(get_post('code_id'), $amount); // This is new line in existing code
$_SESSION['journal_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
$_POST['dimension2_id'], $amount, $_POST['LineMemo'], '', get_post('person_id'));
unset($_SESSION['journal_items']->tax_info);
line_start_focus();
}
abd for updating of exiting entry.
function handle_update_item()
{
if($_POST['UpdateItem'] != "" && check_item_data())
{
if (input_num('AmountDebit') > 0)
$amount = input_num('AmountDebit');
else
$amount = -input_num('AmountCredit');
check_account_selection(get_post('code_id'), $amount); // This is new line in existing code
$_SESSION['journal_items']->update_gl_item($_POST['Index'], $_POST['code_id'],
$_POST['dimension_id'], $_POST['dimension2_id'], $amount, $_POST['LineMemo'], '', get_post('person_id'));
unset($_SESSION['journal_items']->tax_info);
line_start_focus();
}
}
Subscription service based on FA
HRM CRM POS batch Themes