Ejemplo n.º 1
0
 /**
  * split transaction into receivable entries
  *
  * @param $record_template \b bare-bones TBRACCD field array that will be used for all TBRACCD records during transaction processing
  */
 public function split($record_template)
 {
     $this->amount_paid_remaining = $this->amount;
     /**
      * Implementing the below code to work with AR office in an effort 
      * to have student payments only apply to the term that they select 
      * within the online billing app.
      */
     $term_code = $record_template['term_code'] ?: $this->term_code;
     $this->term_payment($term_code, $record_template, $this->amount);
     return $this;
     //------------Currently Ignoring Everything Below Here---------------
     // find the earliest unsatisfied term
     $early_term = $this->person->bill->earliest_unsatisfied_term;
     $only_term_types = array();
     $pre_apply = array();
     $skip = array();
     // populate $only_term_types via filter if filter exists and level has been set
     if (\PSU::has_filter('transaction_term_types') && $this->level) {
         $only_term_types = \PSU::apply_filters('transaction_term_types', $only_term_types, $this->level);
     }
     //end if
     // populate $skip via filter if filter exists
     if (\PSU::has_filter('transaction_term_skip') && $this->level) {
         $skip = \PSU::apply_filters('transaction_term_skip', $skip, $this->person->bill, $this->level);
     }
     //end if
     // populate $pre_apply via filter if filter is set
     if (\PSU::has_filter('transaction_split_pre_apply')) {
         $pre_apply = \PSU::apply_filters('transaction_split_pre_apply', $pre_apply, $this->person->bill);
         // loop over terms to pre-apply payments to
         foreach ($pre_apply as $term => $value) {
             $this->term_payment($term, $record_template, $value);
         }
         //end while
     }
     //end if
     $found_term = false;
     // loop over term balances
     foreach ((array) $this->person->bill->all_term_balances as $term => $value) {
         // find the current term
         if (!$found_term && $term != $early_term) {
             continue;
         } elseif ($term == $early_term) {
             $found_term = true;
         } elseif ($value <= 0) {
             continue;
         }
         // if there are values in $only_term_types then we only want to put
         // transactions in specific terms.  If this term is not in the list
         // of allowable terms, then skip it.
         if (!empty($only_term_types)) {
             if (!in_array(\PSU\Student::term_type($term), $only_term_types)) {
                 continue;
             }
             //end if
         }
         //end if
         // if there are values in $skip then we want to be sure
         // we skip it.
         if (!empty($skip)) {
             if (in_array($term, $skip)) {
                 continue;
             }
             //end if
         }
         //end if
         $this->term_payment($term, $record_template, $value);
     }
     //end while
     // if there is STILL money needing to be posted, prep a dummy term and post
     if ($this->amount_paid_remaining > 0) {
         // We don't want to find old activity, and if we are here, we have applied funds to the current ter,
         // Target the next term specified by the bursar otherwise fall back to this term
         $term = \PSU\AR::bursar_future_term(strtolower($this->level)) ?: $this->person->bill->last_balance_term();
         $payment = $record_template;
         $payment['term_code'] = $term;
         $payment['amount'] = $this->amount_paid_remaining;
         $this->amount_paid_remaining = 0;
         $this->add_entry($payment);
     }
     //end if
     return $this;
 }