/** * Assign all taxes to reservation * * @param RM_Reservation_Row $reservation * @param RM_Reservation_Details_Row $detailRow * @return bool */ function assign(RM_Reservation_Details $detail, RM_Reservation_Details_Row $detailRow) { $detailsPrice = $detail->getTotal(); $summaryModel = new RM_ReservationSummary(); $summaryRows = $summaryModel->fetchByReservationDetail($detailRow); foreach ($summaryRows as $summaryRow) { if ($summaryRow->type !== self::SUMMARY_TYPE) { $detailsPrice += $summaryRow->total_amount; } } $model = new RM_Taxes(); $taxes = $model->getByUnit($detail->getUnit()); foreach ($taxes as $tax) { $summaryModel->insert(array('row_id' => $tax->id, 'type' => self::SUMMARY_TYPE, 'reservation_id' => null, 'reservation_detail_id' => $detailRow->id, 'total_amount' => $tax->calculate($detailsPrice, $detail), 'name' => $tax->getName(RM_Environment::getInstance()->getLocale()))); } }
/** * Validate extras selection for the user GUI * * @param array $data in format [extras system name][unit id][extra id] = user selected value for the extra * @return bool */ public function applySelection(Zend_Controller_Request_Abstract $request, RM_Reservation_Details $detail) { $data = $request->getParam('rm_extras', array()); if (is_array($data) == false) { return false; } if (count($data) == 0) { return $detail; } if (isset($data[$detail->getUnit()->id]) == false) { return $detail; } if (is_array($data[$detail->getUnit()->id]) == false) { return false; } if (count($data[$detail->getUnit()->id]) == 0) { return $detail; } // tax $taxSystem = RM_Environment::getInstance()->getTaxSystem(); $taxes = $taxSystem->getAllTaxes($detail->getUnit()); $model = new RM_Extras(); $extras = array(); foreach ($data[$detail->getUnit()->id] as $extraID => $value) { $extra = $model->find($extraID)->current(); if ($extra == null) { continue; } if ($extra->isBelongTo($detail->getUnit()) == false) { continue; } if (($value > $extra->max || $value < $extra->min) && $value != 0) { continue; } // calculate the tax due on the extra... $extraTotal = $extra->calculateBy($detail->getTotal(), $detail->getPeriod()->getSeconds()); $taxTotal = 0; foreach ($taxes as $tax) { $taxTotal = $taxTotal + $tax->calculate($extraTotal, $detail); } $extraObject = new RM_Extras_Object($extra, $value * $extraTotal, $value, $value * $taxTotal); $extras[] = $extraObject; } $detail->addExtras($extras); return $detail; }