static function getInvoicedQty($order_line_id) { // Gets the total qty invoiced for a PO Line $pilines = new PInvoiceLineCollection(new PInvoiceLine()); $sh = new SearchHandler($pilines, false); $sh->addConstraint(new Constraint('order_line_id', '=', $order_line_id)); $pilines->load($sh); $qty = 0; foreach ($pilines as $line) { $qty += $line->purchase_qty; } return $qty; }
public function delete() { $flash = Flash::Instance(); $db = DB::Instance(); $db->StartTrans(); $result = parent::delete(); // Save the header to update the header totals if ($result && !$this->invoice_detail->save()) { $result = FALSE; $flash->addError('Error updating header'); } if ($result) { // Check if invoice line is linked to received line $poreceivedline = DataObjectFactory::Factory('POReceivedline'); $poreceivedline->loadBy(array('order_id', 'orderline_id'), array($this->purchase_order_id, $this->order_line_id)); if ($poreceivedline->isLoaded()) { // Invoice line is linked to received line so break the link $poreceivedline->invoice_id = $poreceivedline->invoice_number = NULL; if (!$poreceivedline->save()) { $result = FALSE; $flash->addError('Error updating received line'); } } } if ($result) { // Now update the line numbers of following lines $pinvoicelines = new PInvoiceLineCollection($this); $sh = new SearchHandler($pinvoicelines, FALSE); $sh->addConstraint(new Constraint('invoice_id', '=', $this->invoice_id)); $sh->addConstraint(new Constraint('line_number', '>', $this->line_number)); if ($pinvoicelines->update('line_number', '(line_number-1)', $sh) === FALSE) { $flash->addError('Error updating line numbers ' . $db->ErrorMsg()); $result = FALSE; } } if ($result === FALSE) { $db->FailTrans(); } $db->CompleteTrans(); return $result; }