Skip to content

Instantly share code, notes, and snippets.

@vanessaklee
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save vanessaklee/4e2321fa769a19eb760e to your computer and use it in GitHub Desktop.

Select an option

Save vanessaklee/4e2321fa769a19eb760e to your computer and use it in GitHub Desktop.
commission
<?php
function postCommission() {
$rlia = $this->getResLineItems();
$rid = $this->getResItemId();
$skip = false;
$cruise_items = explode(",", CRUISE_CABIN_IDS);
array_push($cruise_items, CRUISE_COMM_PORT_FEES_ITEM_ID);
array_push($cruise_items, CRUISE_COMM_PORT_TAXES_ITEM_ID);
if ($this->isCruise()) {
$api = ApiFactory::getApiByResItemId( $rid );
if ($api) {
$booking = $api->populateBooking(CurrentUser::getId(), $rid, CurrentUser::getCompanyCode());
if ($booking) {
$cabinRetail = $booking->getPricing()->getCruiseCabinRetail();
$c = ResLineItem::getForResitemAndItem($rid, CRUISE_CABIN_IDS);
if ($cabinRetail <= 0){
$commAmt = $booking->getPricing()->getCommissionDue());
$fees = $booking->getPricing()->getPortTaxes();
$f = ResLineItem::getForResitemAndItem($rid, CRUISE_COMM_PORT_FEES_ITEM_ID);
$taxes = $rliarray=ResLineItem::getForResitemAndItem($rid, CRUISE_COMM_PORT_TAXES_ITEM_ID);
$t = ResLineItem::getForResitemAndItem($rid, CRUISE_COMM_PORT_TAXES_ITEM_ID);
// subtract from taxes first
if ($taxes - $commAmt >= 0) {
$t->setWextPrice($taxes - $commAmt);
} else {
$commAmt = $commAmt - $taxes;
$t->setWextPrice(0);
}
// then from fees, if necessary, minus any discounts
if ($commAmt > 0){
$feeAmt = $fees - $this->getDiscountsTotal();
if ($feeAmt - $commAmt >= 0) {
$f->setWextPrice($feeAmt - $commAmt);
} else {
$f->setWextPrice(0);
}
}
$c->postCommission();
$f->postCommission();
$t->postCommission();
$skip = true;
}
}
}
}
}
foreach($rlia as $idx=>$rli) {
if (!in_array($rli->getItem(), $cruise_items) && !$skip) {
$rli->postCommission();
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment