//--------------------------------------------------------------------------------
+function get_gl_wo_cost_trans($trans_id, $person_id=-1)
+{
+ $sql = "SELECT ".TB_PREF."gl_trans.*, ".TB_PREF."chart_master.account_name FROM ".TB_PREF."gl_trans, ".TB_PREF."chart_master
+ WHERE ".TB_PREF."chart_master.account_code=".TB_PREF."gl_trans.account
+ AND ".TB_PREF."gl_trans.type=".systypes::work_order()." AND ".TB_PREF."gl_trans.type_no=$trans_id
+ AND ".TB_PREF."gl_trans.person_type_id=".payment_person_types::WorkOrder();
+ if ($person_id != -1)
+ $sql .= " AND ".TB_PREF."gl_trans.person_id=$person_id";
+ $sql .= " AND amount < 0";
+
+ return db_query($sql, "The gl transactions could not be retrieved");
+}
+
function get_gl_balance_from_to($from_date, $to_date, $account, $dimension=0, $dimension2=0)
{
$from = date2sql($from_date);
return $row[0];
}
+//----------------------------------------------------------------------------------------------------
+function get_balance($account, $dimension, $dimension2, $from, $to, $from_incl=true, $to_incl=true)
+{
+ $sql = "SELECT SUM(IF(amount >= 0, amount, 0)) as debit, SUM(IF(amount < 0, -amount, 0)) as credit, SUM(amount) as balance
+ FROM ".TB_PREF."gl_trans,".TB_PREF."chart_master,".TB_PREF."chart_types, ".TB_PREF."chart_class
+ WHERE ".TB_PREF."gl_trans.account=".TB_PREF."chart_master.account_code AND ".TB_PREF."chart_master.account_type=".TB_PREF."chart_types.id
+ AND ".TB_PREF."chart_types.class_id=".TB_PREF."chart_class.cid AND";
+
+ if ($account != null)
+ $sql .= " account='$account' AND";
+ if ($dimension > 0)
+ $sql .= " dimension_id=$dimension AND";
+ if ($dimension2 > 0)
+ $sql .= " dimension2_id=$dimension2 AND";
+ $from_date = date2sql($from);
+ if ($from_incl)
+ $sql .= " tran_date >= '$from_date' AND";
+ else
+ $sql .= " tran_date > IF(balance_sheet>0 AND balance_sheet<".CL_INCOME.", '0000-00-00', '$from_date') AND";
+ $to_date = date2sql($to);
+ if ($to_incl)
+ $sql .= " tran_date <= '$to_date' ";
+ else
+ $sql .= " tran_date < '$to_date' ";
+
+ $result = db_query($sql,"No general ledger accounts were returned");
+
+ return db_fetch($result);
+}
+
//--------------------------------------------------------------------------------
function get_budget_trans_from_to($from_date, $to_date, $account, $dimension=0, $dimension2=0)
if(!$tax_type) return; // $gl_code is not tax account
$tax = get_tax_type($tax_type);
- if ($gl_code == $tax['sales_gl_code'])
- $amount = -$amount;
+ //if ($gl_code == $tax['sales_gl_code'])
+ // $amount = -$amount;
// we have to restore net amount as we cannot know the base amount
if ($tax['rate'] == 0) {
// display_warning(_("You should not post gl transactions
$todate = date2sql($to);
$sql = "SELECT
- SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
- IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, net_amount*ex_rate,0)) net_output,
- SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
- IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, amount*ex_rate,0)) payable,
- SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
- IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, 0, net_amount*ex_rate)) net_input,
- SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
- IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, 0, amount*ex_rate)) collectible,
+ SUM(IF(trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=2 || trans_type=10 || trans_type=11, net_amount*ex_rate,0)) net_output,
+ SUM(IF(trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=2 || trans_type=10 || trans_type=11, amount*ex_rate,0)) payable,
+ SUM(IF(trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=2 || trans_type=10 || trans_type=11, 0, net_amount*ex_rate)) net_input,
+ SUM(IF(trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=2 || trans_type=10 || trans_type=11, 0, amount*ex_rate)) collectible,
taxrec.rate,
ttype.id,
ttype.name
}
// store tax details if the gl account is a tax account
add_gl_tax_details($journal_item->code_id,
- $trans_type, $trans_id, -$journal_item->amount, 1, $date_, $memo_);
+ ($journal_item->amount < 0.0 ? 2 : 1), $trans_id, -$journal_item->amount, 1, $date_, $memo_);
}
add_comments($trans_type, $trans_id, $date_, $memo_);
if ($is_bank_to)
{
add_bank_trans($trans_type, $trans_id_reverse, $is_bank_to, $ref,
- $reversingDate, $journal_item->amount,
+ $reversingDate, -$journal_item->amount,
0, "", get_company_currency(),
"Cannot insert a destination bank transaction");
}
// store tax details if the gl account is a tax account
add_gl_tax_details($journal_item->code_id,
- $trans_type, $trans_id, $journal_item->amount, 1, $date, $memo_);
+ ($journal_item->amount < 0.0 ? 2 : 1), $trans_id, $journal_item->amount, 1, $date, $memo_);
}
add_comments($trans_type, $trans_id_reverse, $reversingDate, $memo_);