public function make_inactive() { if (!$this->loadData()) { $this->dataError(); sendBack(); } $customer = $this->_uses[$this->modeltype]; $flash = Flash::Instance(); // Check to make sure no-one has updated the customer if ($customer->hasCurrentActivity()) { $flash->addError('Error making customer inactive - customer is still active'); } else { $customer->date_inactive = fix_date(date(DATE_FORMAT)); $db = DB::Instance(); $db->StartTrans(); if (!$customer->save()) { $flash->addError('Error making customer inactive: ' . $db->ErrorMsg()); $db->FailTrans(); } else { // Now close off any open SO Product Lines for the Customer $soproductline = DataObjectFactory::Factory('SOProductline'); $soproductlines = new SOProductlineCollection($soproductline); $sh = new SearchHandler($soproductlines, FALSE); $sh->addConstraintChain($soproductline->currentConstraint()); $sh->addConstraint(new Constraint('slmaster_id', '=', $customer->id)); if ($soproductlines->update('end_date', $customer->date_inactive, $sh) !== FALSE) { $flash->addMessage('Customer marked as inactive'); } else { $flash->addError('Error closing off customer product lines: ' . $db->ErrorMsg()); $db->FailTrans(); } } $db->CompleteTrans(); } sendBack(); }
public function end_lines() { $productlines = new SOProductlineCollection(DataObjectFactory::Factory('SOProductline')); $sh = new SearchHandler($productlines, FALSE); $sh->addConstraint(new Constraint('productline_header_id', '=', $this->id)); $cc = new ConstraintChain(); $cc->add(new Constraint('end_date', 'is', 'NULL')); $cc->add(new Constraint('end_date', '>', $this->end_date), 'OR'); $sh->addConstraint($cc); return $productlines->update('end_date', $this->end_date, $sh); }