public function accrueLine($_ids = '', &$errors = array(), $_reverse_accrual = FALSE) { if (empty($_ids) || !is_array($_ids)) { return FALSE; } $db =& DB::Instance(); $db->StartTrans(); $poreceivedline = DataObjectFactory::Factory('POReceivedLine'); $poreceivedlines = new POReceivedLineCollection($poreceivedline); $sh = new SearchHandler($poreceivedlines, FALSE); $sh->addConstraint(new Constraint('id', 'in', '(' . implode(',', array_keys($_ids)) . ')')); $glparams = DataObjectFactory::Factory('GLParams'); $accrual_control = $glparams->accruals_control_account(); $result = TRUE; if (!empty($accrual_control)) { $cost_centre = $glparams->balance_sheet_cost_centre(); $sh->setFields(array('id', 'glaccount_id', 'glcentre_id', 'item_description', 'net_value', 'order_number', 'rate', 'received_date')); $rows = $poreceivedlines->load($sh, null, RETURN_ROWS); $gltransactions = GLTransaction::makeFromGRN(array('control_glaccount_id' => $accrual_control, 'control_glcentre_id' => $cost_centre, 'reverse_accrual' => $_reverse_accrual), $rows, $errors); if (count($errors) > 0) { $result = FALSE; $errors[] = 'Error saving GL Transaction : ' . $db->ErrorMsg(); } else { // Save the GL Transactions and update the balances if (!GLTransaction::saveTransactions($gltransactions, $errors)) { $result = FALSE; $errors[] = 'Error saving GL Transaction : ' . $db->ErrorMsg(); } } } // Now update the received lines status to accrued if ($result !== FALSE) { if ($_reverse_accrual) { $result = $poreceivedlines->update('status', $poreceivedline->writeOffStatus(), $sh); } else { $result = $poreceivedlines->update('status', $poreceivedline->accrualStatus(), $sh); } if ($result !== FALSE && $result != count($_ids)) { $errors[] = 'Updated ' . $result . ' expected ' . count($_ids); $result = FALSE; } } if ($result === FALSE) { $db->FailTrans(); } $db->CompleteTrans(); return $result; }