Exemplo n.º 1
0
 /**
  * @brief Delete this orderdetails incl. all their pricedetails
  *
  * @throws Exception if there was an error
  */
 public function delete()
 {
     try {
         $transaction_id = $this->database->begin_transaction();
         // start transaction
         // Delete all Pricedetails
         $all_pricedetails = array_reverse($this->get_pricedetails());
         // the last one must be deleted first!
         $this->reset_attributes();
         // set $this->pricedetails to NULL
         foreach ($all_pricedetails as $pricedetails) {
             $pricedetails->delete();
         }
         // Check if this Orderdetails is the Part's selected Orderdetails for ordering and delete this reference if neccessary
         $order_orderdetails = $this->get_part()->get_order_orderdetails();
         if (is_object($order_orderdetails) && $order_orderdetails->get_id() == $this->get_id()) {
             $this->get_part()->set_order_orderdetails_id(NULL);
         } else {
             $this->get_part()->set_attributes(array());
         }
         // save part attributes to update its "last_modified"
         // now we can delete this orderdetails
         parent::delete();
         $this->database->commit($transaction_id);
         // commit transaction
     } catch (Exception $e) {
         $this->database->rollback();
         // rollback transaction
         // restore the settings from BEFORE the transaction
         $this->reset_attributes();
         throw new Exception("Die Einkaufsinformationen konnten nicht gelöscht werden!\nGrund: " . $e->getMessage());
     }
 }
Exemplo n.º 2
0
 /**
  * @brief Delete this pricedetails record
  *
  * @warning     The pricedetails with "min_discount_quantity == 1" cannot be deleted
  *              if there are already other pricedetails! If you want to delete all
  *              pricedetails, you have to delete all other pricedetails first!
  *
  * @throws Exception if it is not allowed to delete this pricedetails
  * @throws Exception if there was an error
  */
 public function delete()
 {
     // Check if it is allowed to delete this pricedetails
     if ($this->get_min_discount_quantity() == 1) {
         $orderdetails = $this->get_orderdetails();
         $all_pricedetails = $orderdetails->get_pricedetails();
         if (count($all_pricedetails) > 1) {
             throw new Exception('Die ausgewählte Preisinformation kann erst gelöscht werden ' . 'wenn es sonst keine weiteren Preisinformationen gibt!');
         }
     }
     // save orderdetails attributes to update its "last_modified" and "last_modified" of the part
     $this->get_orderdetails()->set_attributes(array());
     // now we can delete this orderdetails
     parent::delete();
 }