Exemplo n.º 1
0
 /**
  * This populates the expenses for a monthly-listing from
  * PIREPData::getIntervalDatabyMonth(array(), months). This goes
  * monthly. Pass in just one month returned by that array. 
  * 
  * This will add a index called 'expenses' which will contain
  * all of the expenses for that month	
  *
  * @param mixed $month_info This is a description
  * @return mixed This is the return value description
  *
  */
 public static function calculateFinances($month_info)
 {
     $pilot_pay = LedgerData::getTotalForMonth($month_info->timestamp);
     /* Where the bulk of our work is done for expenses */
     $running_total = 0;
     $expenses = self::getExpensesForMonth($month_info->timestamp);
     foreach ($expenses as $ex) {
         $ex->type = strtolower($ex->type);
         if ($ex->type == 'm') {
             $ex->total = $ex->cost;
         } elseif ($ex->type == 'f') {
             /* per-flight expense */
             $ex->total = $month_info->total * $ex->cost;
         } elseif ($ex->type == 'p') {
             /* percent of gross per month */
             $ex->total = $month_info->gross * ($ex->cost / 100);
         } elseif ($ex->type == 'g') {
             /* perfect revenue, per flight */
             $ex->total = $month_info->gross * ($ex->cost / 100);
         }
         $running_total += $ex->total;
     }
     $month_info->expenses = $expenses;
     $month_info->expenses_total = $running_total;
     $month_info->pilotpay = $pilot_pay;
     $month_info->revenue = $month_info->gross - $month_info->fuelprice - $month_info->pilotpay - $running_total;
     return $month_info;
 }
Exemplo n.º 2
0
 /**
  * Fill in the ledger any PIREPs which might be missing
  * 
  * @param mixed $pilotid
  * @return void
  */
 public static function fillMissingLedgerForPIREPS($pilotid)
 {
     $sql = 'SELECT `pirepid` FROM `' . TABLE_PREFIX . 'pireps`
                 WHERE `pilotid`=' . $pilotid . ' AND `accepted`=' . PIREP_ACCEPTED;
     $res = DB::get_results($sql);
     foreach ($res as $pirep) {
         $exists = LedgerData::getPaymentByPIREP($pirep->pirepid);
         if (!$exists) {
             PIREPData::calculatePIREPPayment($pirep->pirepid);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * SchedulePIREPTest::checkPIREP()
  * 
  * @param mixed $pirepdata
  * @return void
  */
 protected function checkPIREP($pirep_test, $pirepid)
 {
     $sched = $this->findSchedule();
     $pirepdata = PIREPData::findPIREPS(array('p.pirepid' => $pirepid));
     $pirepdata = $pirepdata[0];
     $this->checkPIREPFinances($pirep_test, $pirepdata);
     # Check the pilot pay
     $pilot_data = PilotData::getPilotData($this->samplePilotID);
     # Change PIREP Status
     $status = PIREPData::changePIREPStatus($pirepdata->pirepid, PIREP_ACCEPTED);
     $pirepdata = PIREPData::findPIREPS(array('p.pirepid' => $pirepid));
     $this->assertEquals(PIREP_ACCEPTED, $pirepdata[0]->accepted, 'changePIREPStatus to ACCEPTED');
     $pirepdata = $pirepdata[0];
     # Check the schedule flown count:
     $post_accept = $this->findSchedule();
     $this->assertEquals($sched->timesflown + 1, $post_accept->timesflown, "Schedule increment count");
     # Check the pilot pay
     $post_pilot_data = PilotData::getPilotData($this->samplePilotID);
     $pay_log = LedgerData::getPaymentByPIREP($pirepid);
     if ($pirepdata->paytype == PILOT_PAY_SCHEDULE) {
         $this->assertEquals($this->sample_schedule['payforflight'], $pirepdata->pilotpay, 'PIREP Pay Amount');
         $this->assertEquals($this->sample_schedule['payforflight'], $pay_log->amount, 'Check pilot pay after PIREP ACCEPT');
     } else {
         $this->assertEquals(PilotData::getPilotPay($this->sample_schedule['flighttime'], $pilot_data->payrate), $pay_log->amount, 'Check pilot pay after PIREP ACCEPT');
     }
     $this->assertEquals($pilot_data->totalflights + 1, $post_pilot_data->totalflights, 'Total Flights');
     # Check total hours
     $this->assertGreaterThan($pilot_data->totalhours, $post_pilot_data->totalhours, 'Checking total hours');
     # Reject the PIREP and then check the pilot pay
     $status = PIREPData::changePIREPStatus($pirepdata->pirepid, PIREP_REJECTED);
     $pirepdata = PIREPData::findPIREPS(array('p.pirepid' => $pirepid));
     $this->assertEquals(PIREP_REJECTED, $pirepdata[0]->accepted, 'changePIREPStatus to REJECTED');
     $pirepdata = $pirepdata[0];
     # Check the schedule flown count:
     $post_accept = $this->findSchedule();
     $this->assertEquals($sched->timesflown, $post_accept->timesflown, "Schedule increment count");
     $post_pilot_data = PilotData::getPilotData($this->samplePilotID);
     $this->assertEquals($pilot_data->totalpay, $post_pilot_data->totalpay, 'Check pilot pay after PIREP REJECT');
     $this->assertEquals($pilot_data->totalflights, $post_pilot_data->totalflights, 'Total Flights after REJECT');
     # Delete the PIREP
     PIREPData::deletePIREP($pirepid);
     # Verify delete
     $data = PIREPData::findPIREPS(array('p.pirepid' => $pirepid));
     $this->assertEmpty($data, 'PIREPDdata::deletePIREP()');
 }
Exemplo n.º 4
0
 /**
  * Add a payment for a PIREP.
  * 
  * @param int $pirepid PIREP ID
  * @return
  */
 public static function calculatePIREPPayment($pirepid)
 {
     $pirep = DB::get_row('SELECT `pirepid`, `pilotid`, 
                 `flighttime_stamp`, `pilotpay`, 
             `paytype`, `flighttype`, `accepted`
         FROM `' . TABLE_PREFIX . 'pireps`
         WHERE `pirepid`=' . $pirepid);
     if ($pirep->accepted == PIREP_REJECTED) {
         return false;
     }
     if ($pirep->paytype == PILOT_PAY_HOURLY) {
         # Price out per-hour?
         $peices = explode(':', $pirep->flighttime_stamp);
         $minutes = $peices[0] * 60 + $peices[1];
         $amount = $minutes * ($pirep->pilotpay / 60);
     } elseif ($pirep->paytype == PILOT_PAY_SCHEDULE) {
         $amount = $pirep->pilotpay;
     }
     $params = array('pirepid' => $pirepid, 'pilotid' => $pirep->pilotid, 'paysource' => PAYSOURCE_PIREP, 'paytype' => $pirep->paytype, 'amount' => $amount);
     $entry = LedgerData::getPaymentByPIREP($pirepid);
     if (!$entry) {
         LedgerData::addPayment($params);
     } else {
         LedgerData::editPayment($entry->id, $params);
     }
     PilotData::resetPilotPay($pirep->pilotid);
     return $amount;
 }
Exemplo n.º 5
0
<?php

include dirname(__FILE__) . '/bootstrap.inc.php';
echo '<pre>';
$sql = 'UPDATE `' . TABLE_PREFIX . 'pireps` SET `accepted`=' . PIREP_PENDING . ' WHERE `pirepid`=2';
DB::query($sql);
PIREPData::changePIREPStatus(2, PIREP_ACCEPTED);
var_dump(LedgerData::getPaymentByPIREP(2));