Beispiel #1
0
 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) {
         // Now update the line numbers of following lines
         $sinvoicelines = new SInvoiceLineCollection($this);
         $sh = new SearchHandler($sinvoicelines, false);
         $sh->addConstraint(new Constraint('invoice_id', '=', $this->invoice_id));
         $sh->addConstraint(new Constraint('line_number', '>', $this->line_number));
         if ($sinvoicelines->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;
 }
Beispiel #2
0
 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;
 }