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; }
public function post(&$errors = array()) { $db = DB::Instance(); $db->StartTrans(); $result = parent::post($errors); if ($result) { $receivedlines = new POReceivedLineCollection(DataObjectFactory::Factory('POReceivedLine')); $sh = new SearchHandler($receivedlines, FALSE); $sh->addConstraint(new Constraint('invoice_id', '=', $this->{$this->idField})); $result = $receivedlines->update('status', 'I', $sh); if ($result === FALSE) { $errors[] = 'Error updating GRN status'; } } if ($result === FALSE) { $errors[] = $db->ErrorMsg(); $db->FailTrans(); } $db->completeTrans(); return $result; }
public function print_label() { $poreceivedline = DataObjectFactory::Factory('POReceivedline'); if (isset($this->_data['id'])) { $poreceivedline->load($this->_data['id']); } elseif (isset($this->_data['gr_number'])) { $poreceivedline->loadBy('gr_number', $this->_data['gr_number']); } if (!$poreceivedline->isLoaded()) { $flash = Flash::Instance(); $flash->addError('Error getting Goods Received Note details'); sendTo($this->name, 'index', $this->_modules); } $porder = DataObjectFactory::Factory('POrder'); $porder->load($poreceivedline->order_id); $this->view->set('grn', $poreceivedline); $this->view->set('POrder', $porder); $poreceivedlines = new POReceivedLineCollection(); $poreceivedlines->getReceivedLines($poreceivedline->gr_number); $this->view->set('POReceivedlines', $poreceivedlines); $this->view->set('printers', $this->selectPrinters()); $this->view->set('default_printer', $this->getDefaultPrinter()); $sidebar = new SidebarController($this->view); $actions = array(); $actions['viewnotes'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'index'), 'tag' => 'view goods received notes'); $actions['confirm'] = array('link' => array('modules' => $this->_modules, 'controller' => $this->name, 'action' => 'viewAwaitingDelivery', 'type' => 'confirm'), 'tag' => 'Confirm Delivery'); $sidebar->addList('Actions', $actions); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); }
function populate() { $poreceived = new POReceivedLineCollection(); $receivedSum = $poreceived->getReceivedSum(3); $this->contents = $receivedSum; }