Apply credits

@param array  $data
@param Person $person
160090
protected function applyCredits(array $data, Person $person)
    {
        $hydrator = new ObjectHydrator();
        $types    = ['movie_credits', 'tv_credits', 'combined_credits'];

        foreach ($types as $type) {
            if (array_key_exists($type, $data)) {
                $method = $hydrator->camelize(sprintf('get_%s', $type));

                if (array_key_exists('cast', $data[$type])) {
                    $cast = $this->createCustomCollection(
                        $data[$type]['cast'],
                        new Person\Credit(),
                        new People\Cast()
                    );

                    foreach ($cast as $member) {
                        $member->setPosterImage($this->getPosterImageForCredit($member->getPosterPath()));
                    }

                    $person->$method()->setCast($cast);
                }

                if (array_key_exists('crew', $data[$type])) {
                    $crew = $this->createCustomCollection(
                        $data[$type]['crew'],
                        new Person\Credit(),
                        new People\Crew()
                    );

                    foreach ($crew as $member) {
                        $member->setPosterImage($this->getPosterImageForCredit($member->getPosterPath()));
                    }

                    $person->$method()->setCrew($crew);
                }
            }
        }
    }
1205900
public function process_user_competency_course($data) {
        global $USER, $DB;
        $data = (object) $data;

        $data->competencyid = $this->get_mappingid(\core_competency\competency::TABLE, $data->competencyid);
        if (!$data->competencyid) {
            // This is strange, the competency does not belong to the course.
            return;
        } else if ($data->grade === null) {
            // We do not need to do anything when there is no grade.
            return;
        }

        $data->userid = $this->get_mappingid('user', $data->userid);
        $shortname = $DB->get_field('course', 'shortname', array('id' => $this->task->get_courseid()), MUST_EXIST);

        // The method add_evidence also sets the course rating.
        \core_competency\api::add_evidence($data->userid,
                                           $data->competencyid,
                                           $this->task->get_contextid(),
                                           \core_competency\evidence::ACTION_OVERRIDE,
                                           'evidence_courserestored',
                                           'core_competency',
                                           $shortname,
                                           false,
                                           null,
                                           $data->grade,
                                           $USER->id);
    }
100538
public function process_gradingform_rubric_level($data) {
        global $DB;

        $data = (object)$data;
        $oldid = $data->id;
        $data->criterionid = $this->get_new_parentid('gradingform_rubric_criterion');

        $newid = $DB->insert_record('gradingform_rubric_levels', $data);
        $this->set_mapping('gradingform_rubric_level', $oldid, $newid);
    }
1099628
protected function process_grading_definition($data) {
        global $DB;

        $task = $this->get_task();
        $data = (object)$data;
        $oldid = $data->id;
        $data->areaid = $this->get_new_parentid('grading_area');
        $data->copiedfromid = null;
        $data->timecreated = time();
        $data->usercreated = $task->get_userid();
        $data->timemodified = $data->timecreated;
        $data->usermodified = $data->usercreated;

        $newid = $DB->insert_record('grading_definitions', $data);
        $this->set_mapping('grading_definition', $oldid, $newid, true);
    }
1302933
function addCreditToCredits(credits, person, name) {
	let credit = getCredit(credits, person);

	if (!credit) {
		credit = person;
		credit.packages = [];

		credits.push(credit);
	}

	if (credit.packages.indexOf(name) === -1) {
		credit.packages.push(name);
	}

	return credits;
}
191647
function update_credit_account($i) {
    global $db, $order, $insert_id;
    // only act on newly-purchased gift certificates
    if (preg_match('/^GIFT/', addslashes($order->products[$i]['model']))) {
      // determine how much GV was purchased
      $gv_order_amount = ($order->products[$i]['final_price'] * $order->products[$i]['qty']);
      // if tax is to be calculated on purchased GVs, calculate it
      if ($this->credit_tax=='true') $gv_order_amount = $gv_order_amount * (100 + $order->products[$i]['tax']) / 100;
      $gv_order_amount = $gv_order_amount * 100 / 100;

      if (MODULE_ORDER_TOTAL_GV_QUEUE == 'false') {
        // GV_QUEUE is false so release amount to account immediately
        $gv_result = $this->user_has_gv_account($_SESSION['customer_id']);
        $customer_gv = false;
        $total_gv_amount = 0;
        if ($gv_result) {
          $total_gv_amount = $gv_result;
          $customer_gv = true;
        }
        $total_gv_amount = $total_gv_amount + $gv_order_amount;
        if ($customer_gv) {
          $db->Execute("update " . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $total_gv_amount . "' where customer_id = '" . (int)$_SESSION['customer_id'] . "'");
        } else {
          $db->Execute("insert into " . TABLE_COUPON_GV_CUSTOMER . " (customer_id, amount) values ('" . (int)$_SESSION['customer_id'] . "', '" . $total_gv_amount . "')");
        }
      } else {
        // GV_QUEUE is true - so queue the gv for release by store owner
        $db->Execute("insert into " . TABLE_COUPON_GV_QUEUE . " (customer_id, order_id, amount, date_created, ipaddr) values ('" . (int)$_SESSION['customer_id'] . "', '" . (int)$insert_id . "', '" . $gv_order_amount . "', NOW(), '" . $_SERVER['REMOTE_ADDR'] . "')");
      }
    }
  }
326878
public function process_course($data) {
        global $CFG, $DB;
        $context = context::instance_by_id($this->task->get_contextid());
        $userid = $this->task->get_userid();
        $target = $this->get_task()->get_target();
        $isnewcourse = $target == backup::TARGET_NEW_COURSE;

        // When restoring to a new course we can set all the things except for the ID number.
        $canchangeidnumber = $isnewcourse || has_capability('moodle/course:changeidnumber', $context, $userid);
        $canchangesummary = $isnewcourse || has_capability('moodle/course:changesummary', $context, $userid);
        $canforcelanguage = has_capability('moodle/course:setforcedlanguage', $context, $userid);

        $data = (object)$data;
        $data->id = $this->get_courseid();

        // Calculate final course names, to avoid dupes.
        $fullname  = $this->get_setting_value('course_fullname');
        $shortname = $this->get_setting_value('course_shortname');
        list($data->fullname, $data->shortname) = restore_dbops::calculate_course_names($this->get_courseid(),
            $fullname === false ? $data->fullname : $fullname,
            $shortname === false ? $data->shortname : $shortname);
        // Do not modify the course names at all when merging and user selected to keep the names (or prohibited by cap).
        if (!$isnewcourse && $fullname === false) {
            unset($data->fullname);
        }
        if (!$isnewcourse && $shortname === false) {
            unset($data->shortname);
        }

        // Unset summary if user can't change it.
        if (!$canchangesummary) {
            unset($data->summary);
            unset($data->summaryformat);
        }

        // Unset lang if user can't change it.
        if (!$canforcelanguage) {
            unset($data->lang);
        }

        // Only allow the idnumber to be set if the user has permission and the idnumber is not already in use by
        // another course on this site.
        if (!empty($data->idnumber) && $canchangeidnumber && $this->task->is_samesite()
                && !$DB->record_exists('course', array('idnumber' => $data->idnumber))) {
            // Do not reset idnumber.

        } else if (!$isnewcourse) {
            // Prevent override when restoring as merge.
            unset($data->idnumber);

        } else {
            $data->idnumber = '';
        }

        // Any empty value for course->hiddensections will lead to 0 (default, show collapsed).
        // It has been reported that some old 1.9 courses may have it null leading to DB error. MDL-31532
        if (empty($data->hiddensections)) {
            $data->hiddensections = 0;
        }

        // Set legacyrestrictmodules to true if the course was resticting modules. If so
        // then we will need to process restricted modules after execution.
        $this->legacyrestrictmodules = !empty($data->restrictmodules);

        $data->startdate= $this->apply_date_offset($data->startdate);
        if (isset($data->enddate)) {
            $data->enddate = $this->apply_date_offset($data->enddate);
        }

        if ($data->defaultgroupingid) {
            $data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid);
        }
        if (empty($CFG->enablecompletion)) {
            $data->enablecompletion = 0;
            $data->completionstartonenrol = 0;
            $data->completionnotify = 0;
        }
        $languages = get_string_manager()->get_list_of_translations(); // Get languages for quick search
        if (isset($data->lang) && !array_key_exists($data->lang, $languages)) {
            $data->lang = '';
        }

        $themes = get_list_of_themes(); // Get themes for quick search later
        if (!array_key_exists($data->theme, $themes) || empty($CFG->allowcoursethemes)) {
            $data->theme = '';
        }

        // Check if this is an old SCORM course format.
        if ($data->format == 'scorm') {
            $data->format = 'singleactivity';
            $data->activitytype = 'scorm';
        }

        // Course record ready, update it
        $DB->update_record('course', $data);

        course_get_format($data)->update_course_format_options($data);

        // Role name aliases
        restore_dbops::set_course_role_names($this->get_restoreid(), $this->get_courseid());
    }
1054743
protected function proceedPerson(array $person)
    {

        // If "Gerrit Code Review" posted some problems, e.g. path conflicts (e.g. https://review.typo3.org/#/c/4553/)
        // there is no person information.
        // Set it here, because otherwise we got empty persons ;)
        if (array_key_exists('name', $person) === false &&
            array_key_exists('email', $person) === false &&
            array_key_exists('username', $person) === false
        ) {

            $person['name'] = 'Unknown (Exporter)';
            $person['email'] = 'mail@example.org';
            $person['username'] = 'Unknown_export_username';
        }

        // Sometimes the person got no name.
        // We have to set a default one
        if (array_key_exists('name', $person) === false) {
            $person['name'] = 'Unknown (Exporter)';
        }

        if (array_key_exists('username', $person) === false) {
            $person['username'] = 'Unknown_export_username';
        }

        // Sometimes you got an action by "Gerrit Code Review".
        // This "system user" does not have a username. Sad, isn`t ?
        // We got a present for him / her. A default username :)
        // e.g. https://review.typo3.org/#/c/4553/
        if ($person['name'] === 'Gerrit Code Review') {
            $person['username'] = 'Gerrit';
        }

        // Sometimes the API does not return an email
        $email = '';
        $emailPerson = false;
        if (array_key_exists('email', $person) !== false) {
            $email = $person['email'];
            $emailPerson = $this->getPersonBy('email', $person['email']);
        }

        if ($emailPerson === false) {

            $personByName = false;
            if ($person['username']) {
                $personByName = $this->getPersonBy('username', $person['username']);

            } elseif ($person['name']) {
                $personByName = $this->getPersonBy('name', $person['name']);
            }

            // If a person does not exist, create a new one.
            if ($personByName === false) {
                $personData = array(
                    'name' => $person['name'],
                    'username' => $person['username']
                );
                $person['id'] = $this->getDatabase()->insertRecord(Database::TABLE_PERSON, $personData);

                $emailData = array(
                    'person' => $person['id'],
                    'email' => $email
                );
                $this->getDatabase()->insertRecord(Database::TABLE_EMAIL, $emailData);

                // Person exists, but has a new e-mail. Just add the e-mail-address to this person
            } else {
                $person['id'] = $personByName['id'];
                $emailData = array(
                    'person' => $personByName['id'],
                    'email' => $email
                );
                $this->getDatabase()->insertRecord(Database::TABLE_EMAIL, $emailData);
            }
        } else {
            $person['id'] = $emailPerson['id'];
        }

        return $person;
    }
919853
public function applyPayments(string $id, array $data, array $headers = [])
    {
        $url = $this->url('invoices/%s/apply_payments', $id);

        return $this->post($url, $data, $headers);
    }
990654
protected function getCallBackUser($data)
    {
        // simulating user object
        $user = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
        $user->initializeUserForCallBackPayPalUser($data);

        return $user;
    }
1021956
protected function process_assign($data) {
        global $DB;

        $data = (object)$data;
        $oldid = $data->id;
        $data->course = $this->get_courseid();

        // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
        // See MDL-9367.
        $data->allowsubmissionsfromdate = $this->apply_date_offset($data->allowsubmissionsfromdate);
        $data->duedate = $this->apply_date_offset($data->duedate);

        // If this is a team submission, but there is no group info we need to flag that the submission
        // information should not be included. It should not be restored.
        $groupinfo = $this->task->get_setting_value('groups');
        if ($data->teamsubmission && !$groupinfo) {
            $this->includesubmission = false;
        }

        // Reset revealidentities if blindmarking with no user data (MDL-43796).
        $userinfo = $this->get_setting_value('userinfo');
        if (!$userinfo && $data->blindmarking) {
            $data->revealidentities = 0;
        }

        if (!empty($data->teamsubmissiongroupingid)) {
            $data->teamsubmissiongroupingid = $this->get_mappingid('grouping',
                                                                   $data->teamsubmissiongroupingid);
        } else {
            $data->teamsubmissiongroupingid = 0;
        }

        if (!isset($data->cutoffdate)) {
            $data->cutoffdate = 0;
        }
        if (!isset($data->gradingduedate)) {
            $data->gradingduedate = 0;
        } else {
            $data->gradingduedate = $this->apply_date_offset($data->gradingduedate);
        }
        if (!isset($data->markingworkflow)) {
            $data->markingworkflow = 0;
        }
        if (!isset($data->markingallocation)) {
            $data->markingallocation = 0;
        }
        if (!isset($data->preventsubmissionnotingroup)) {
            $data->preventsubmissionnotingroup = 0;
        }

        if (!empty($data->preventlatesubmissions)) {
            $data->cutoffdate = $data->duedate;
        } else {
            $data->cutoffdate = $this->apply_date_offset($data->cutoffdate);
        }

        if ($data->grade < 0) { // Scale found, get mapping.
            $data->grade = -($this->get_mappingid('scale', abs($data->grade)));
        }

        $newitemid = $DB->insert_record('assign', $data);

        $this->apply_activity_instance($newitemid);
    }
313928
public function planLoan($data)
    {
        $GLOBALS[debug][stopwatch]='plan_loan';
        //echo $this->html->pre_display($data,"f:plan_loan");
        //$days_add=$this->dates->F_datediff($data[df],$data[dt]);
        //echo "$days_add<br>";
        $res=$data;
        if ($data[base]=='365') {
            $daysinyear=365;
        } else {
            $daysinyear=360;
        }
        if ($data[base]=='') {
            $data[base]='30/360';
        }
        $periods=$data['periods'];
        if ($periods==0) {
            $periods=1;
        }
        $payments=$data['payments'];
        $payment_range=round($periods/$payments);

        if (($payment_range==0)||($payment_range==INF)) {
            $payment_range=1;
        }
        //echo $this->html->pre_display($payment_range,"payment_range");
        $days_loan=$this->dates->F_datediff($data[df], $data[dt], $data[base]);
        $data[days_loan]=$days_loan;
        $months_loan=$days_loan/365*12;
        $pays_per_year=$data[freq];

        if (($days_loan>366)&&($data[freq]==1)&&($data[periods]==1)) {
            $pays_per_year=365/$days_loan;
        }
        $data[pays_per_year]=$pays_per_year;
        $data[months_loan]=$months_loan;
        $months_loan_rounded=round($months_loan);
        $data[months_loan_rounded]=$months_loan_rounded;
        //echo $this->html->pre_display($data,"F:plan_loan");
        //echo "D:$payment_range<br>";
        $fields=array('#','Action','date','Given','Payment','Pcpl. paid','int.Paid','Balance','Ineterest','rate','days','');
        $tbl=$this->html->tablehead($what, $qry, $order, $addbutton, $fields, $sort);
        $i=0;
        $no=1;
        $date=$data[df];
        $pmt_amount=$data[pmt];
        if (($payment_range>=1)&&($pmt_amount==0)&&($payments>0)) {
            $pmt_amount=round($data[amount]/$payments, 2);
        }
        $pmt=0;
        $balance=$data[amount];
        $tbl.="<tr class='$class'><td>$no</td>
<td>Loan</td>
<td>$date</td>
<td class='n'>".$this->html->money($data[amount])."</td>
<td class='n'>".$this->html->money(0)."</td>
<td class='n'>".$this->html->money(0)."</td>
<td class='n'>".$this->html->money(0)."</td>
<td class='n'>".$this->html->money($balance)."</td>
<td class='n'>".$this->html->money(0)."</td>
<td class='n'>".$this->html->money($data['rate']*100)." %</td>
<td class='n'>0</td>
<td>$notes</td>
</tr>";
        $found=0;
        if ($this->dates->is_earlier($data['date'], $data['df'])) {
            $found=1;
        }

        $plan[]=array(
        'no'=>$no,
        'action'=>'Loan',
        'date'=>$date,
        'given'=>$data[amount],
        'returned'=>0,
        'int_paid'=>0,
        'balance'=>$balance,
        'interest'=>0,
        'rate'=>$data['rate'],
        'days'=>0,
        't_given'=>$data[amount],
        't_returned'=>0,
        't_interest'=>0,
        't_paid'=>0,
        'info'=>'',
        );
        if ($data['align']>0) {
            $no++;
            $date_prev=$date;
            if ($data['align']<32) {
                $day=substr($date, 0, 2);
                //echo "$day<br>";
                if ($data['align']>=$day) {
                    $days_add=$data['align']-$day;
                } else {
                    $days_add=$data['align']-$day + $this->days_in_month($date);
                }
                $align_text="$data[align] day of the month";
            } else {
                $days_add=$this->dates->F_datediff($date, $this->dates->lastday_in_month($date));
                $align_text="the last day of the month";
            }
    
            $date=$this->dates->F_dateadd($date, $days_add);
            $data4interest=array(
            'amount'=>$balance,
            'rate'=>$data['rate'],
            'freq'=>$data['freq'],
            'df'=>$date_prev,
            'dt'=>$date,
            'base'=>$data[base],
            'compound'=>$data[compound],
            'note'=>'Plan Loan. Allign.',
            );

            $calc_interest=$this->interest->getInterest($data4interest);
            $interest=$calc_interest[interest];
            if ($pmt>0) {
                $amount=$pmt-$interest;
            } else {
                $amount=0;
            }
            $balance_prev=$balance;
            $balance=$balance-$amount;
            $days=$this->dates->F_datediff($date_prev, $date, $data[base]);
            $days_chk=$this->dates->F_datediff($date, $data['date']);
    
            $notes='';
            //$notes=$this->html->pre_display($calc_interest);
            if (($days_chk<=0)&&($found==0)) {
                $found=1;
                $res[balance]=$balance_prev;
                $res[interest]=$interest;
                $res[t_paid]=$t_paid;
                $res[t_interest_paid]=$t_interest_paid;
                $res[t_principal_paid]=$t_principal_paid;
                $res[next_payment]=$date;
                $res[days_till_next]=-$days_chk;
                //$info=$this->html->pre_display($res);
                //$notes="<span class='badge red'>DATE $data[date]</span> $info";
            }
            $t_paid+=$pmt;
            $t_interest_paid+=$interest;
            $t_principal_paid+=$amount;
            $total=$amount+$interest;
            $t_days+=$days;
            $tbl.="<tr class='$class'><td>$no</td>
	<td>Pay</td>
	<td>$date</td>
	<td class='n'>".$this->html->money(0)."</td>
	<td class='n'>".$this->html->money($total)."</td>
	<td class='n'>".$this->html->money($amount)."</td>
	<td class='n'>".$this->html->money($interest)."</td>
	<td class='n'>".$this->html->money($balance)."</td>
	<td class='n'>".$this->html->money($interest)."</td>
	<td class='n'>".$this->html->money($data['rate']*100)." %</td>
	<td class='n'>$days</td>
	<td>Aligned to $align_text $notes</td>
	</tr>";
            $plan[]=array(
            'no'=>$no,
            'action'=>'Pay',
            'date'=>$date,
            'given'=>0,
            'returned'=>$amount,
            'int_paid'=>$interest,
            'balance'=>$balance,
            'interest'=>$interest,
            'rate'=>$data['rate'],
            'days'=>$days,
            't_given'=>$data[amount],
            't_returned'=>$t_principal_paid,
            't_interest'=>$t_interest_paid,
            't_paid'=>$t_interest_paid+$t_principal_paid,
            'info'=>'',
                );
        }
    //if($pays_per_year>1)$months=12/$months_loan; else $months=12;
        if ($pays_per_year>1) {
            $months=12/$pays_per_year;
        } else {
            $months=12;
        }
        //echo "pays_per_year=$pays_per_year / $months_loan ($months)<br>";
        for ($i=1; $i<=$periods; $i++) {
            $no++;
            $date_prev=$date;
            if ($months>1) {
                //echo "$months / $days_loan<br>";
                if ($pays_per_year>=1) {
                    $date=$this->dates->F_dateadd_month($date, $months);
                } else {
                    $date=$this->dates->F_dateadd($date, $days_loan);
                    //echo "DL:$days_loan<br>";
                }
            
                if ($days_add>0) {
                    $date=$this->dates->lastday_in_month($this->dates->F_dateadd($date, -15));
                }
                if (($days_add>0)&&($i==$periods)) {
                    $date=$this->dates->F_dateadd($date, -$days_add);
                }
                //if($no>=5)echo $this->html->pre_display(['Date'=>$date,'Days_add'=>$days_add],"result4");
            } else {
                $days_in_month=$this->dates->days_in_month_date($this->dates->F_dateadd($date, 15));
                if (($days_add>0)&&($i==$periods)) {
                    $days_in_month=$days_in_month-$days_add;
                }
                $date=$this->dates->F_dateadd($date, $days_in_month);
                //$date=$this->dates->F_dateadd_month($date,$months);
            }

            $days_chk=$this->dates->F_datediff($date, $data['date']);
    
            $notes='';
            //$notes=$this->html->pre_display($calc_interest);
            if (($days_chk<=0)&&($found==0)) {
                $data4interest=array(
                'amount'=>$balance,
                'rate'=>$data['rate'],
                'freq'=>$data['freq'],
                'df'=>$date_prev,
                'dt'=>$data[date],
                'base'=>$data[base],
                'compound'=>$data[compound],
                'note'=>'Plan Loan. Main No '.$no,
                );

                $calc_interest=$this->interest->getInterest($data4interest);
                $found=1;
        
                $res[balance]=$balance_prev;
                $res[interest]=$calc_interest[interest];
                $res[t_paid]=$t_paid;
                $res[t_interest_paid]=$t_interest_paid+$res[interest];
                $res[t_principal_paid]=$t_principal_paid;
                $res[next_payment]=$date;
                $res[days_till_next]=-$days_chk;
                //$info=$this->html->pre_display($res);
                $info.="<table>
		<tr><td>Balance:</td><td class='n'>".$this->html->money($res[balance])."</td></tr>
		<tr><td>Interest:</td><td class='n'>".$this->html->money($res[interest])."</td></tr>
		<tr><td>Interest acc:</td><td class='n'>".$this->html->money($res[t_interest_paid])."</td></tr>
		<tr><td>DTNP:</td><td class='n'>$res[days_till_next]</td></tr>
		</table>";
                $notes="<span class='label'>DATE $data[date]</span><br><span class=''>$info</span>";
            }

            $data4interest=array(
            'amount'=>$balance,
            'rate'=>$data['rate'],
            'freq'=>$data['freq'],
            'df'=>$date_prev,
            'dt'=>$date,
            'base'=>$data[base],
            'compound'=>$data[compound],
            'note'=>'Plan Loan. Final',
            );

            $calc_interest=$this->interest->getInterest($data4interest);
            $interest=$calc_interest[interest];
            $pmt=(($i%$payment_range)==0)?$pmt_amount:0;
            //echo "I.$i=".($i%$payment_range)."<br>";
            if (($pmt==0)&&($i==$periods)) {
                $pmt=$balance+$interest;
            }
            if ($pmt>0) {
                $amount=$pmt-$interest;
            } else {
                $amount=0;
            }
            if (($payment_range>1)&&($pmt>0)) {
                $amount=$pmt;
            }
            $balance_prev=$balance;
            $balance=$balance-$amount;
            $days=$this->dates->F_datediff($date_prev, $date, $data[base]);

            $t_paid+=$pmt;
            $t_interest_paid+=$interest;
    
            $t_principal_paid+=$amount;
            $total=$amount+$interest;
            $t_total_paid+=$total;
            $t_days+=$days;
            $tbl.="<tr class='$class'><td>$no</td>
	<td>Pay</td>
	<td>$date</td>
	<td class='n'>".$this->html->money(0)."</td>
	<td class='n'>".$this->html->money($total)."</td>
	<td class='n'>".$this->html->money($amount)."</td>
	<td class='n'>".$this->html->money($interest)."</td>
	<td class='n'>".$this->html->money($balance)."</td>
	<td class='n'>".$this->html->money($interest)."</td>
	<td class='n'>".$this->html->money($data['rate']*100)." %</td>
	<td class='n'>$days</td>
	<td>$notes</td>
	</tr>";
            $plan[]=array(
            'no'=>$no,
            'action'=>'Pay',
            'date'=>$date,
            'given'=>0,
            'returned'=>$amount,
            'int_paid'=>$interest,
            'balance'=>$balance,
            'interest'=>$interest,
            'rate'=>$data['rate'],
            'days'=>$days,
            't_given'=>$data[amount],
            't_returned'=>$t_principal_paid,
            't_interest'=>$t_interest_paid,
            't_paid'=>$t_interest_paid+$t_principal_paid,
            'info'=>'',
                );
        }
        $totals=array_fill(0, 10, 0);
        $totals[2]=$data[amount];
        $totals[3]=$t_total_paid;
        $totals[4]=$t_principal_paid;
        $totals[5]=$t_interest_paid;
    //$totals[6]=$balance;
        $totals[9]=$t_days;
        $tbl.=$this->html->tablefoot($i, $totals, $no);
        $res[rows]=$no;
        $res[amount_total]=$plan[$no-1][t_given];
        $res[amount_returned_total]=$plan[$no-1][t_returned];
        $res[amount_interest_total]=$plan[$no-1][t_interest];
        $res[amount_paid_total]=$plan[$no-1][t_paid];
        if (($res[interest]==0)&&($found==0)) {
            $res[interest]=$res[amount_interest_total];
        }


        if ($found==0) {
            $res[balance]=$res[amount_total]-$res[amount_returned_total];
            $res[interest]=$interest;
            $res[t_paid]=$res[amount_paid_total];
            $res[t_interest_paid]=$res[amount_interest_total];
            $res[t_principal_paid]=$res[amount_returned_total];
            $res[next_payment]=$dt;
            $res[days_till_next]=0;
        }
        $res[amount_returned_total]=round($res[amount_returned_total], 2);
        $res[amount_interest_total]=round($res[amount_interest_total], 2);
        $res[balance]=round($res[balance], 2);
        $res[interest]=round($res[interest], 2);
        $res[t_paid]=round($res[t_paid], 2);
        $res[t_interest_paid]=round($res[t_interest_paid], 2);
        $res[t_principal_paid]=round($res[t_principal_paid], 2);
        $res[amount_paid_total]=round($res[amount_paid_total], 2);

        $res[days]=$t_days;
        $res[tbl]=$tbl;
        $res[plan]=$plan;

        return $res;
    }
1356742
public void setPerson(Person person) {
		log.debug("Adding person: " + person);
		if (person.getId() == -1) {
			person.setId(getNextId());
		}

		people.remove(person);
		people.add(person);
	}
862248
public function setPersonInfo(string $person_id, string $person_name, string $tag)
    {
        return Request::exec(self::SET_PERSON_INFO, compact('person_id', 'person_name', 'tag'));
    }
40085
public function update(array $data)
    {
        $project_id = (int) (empty($data['project_id']) ? 0: $data['project_id']);
        $person_id = (int) (empty($data['person_id']) ? 0: $data['person_id']);
        if ($project_id <= 0) {
            throw new Exception("Required field project_id");
        }
        if ($person_id <= 0) {
            throw new Exception("Required field person_id");
        }
        return $this->rest->put("projects/$project_id/people/$person_id", $data);
    }
926389
public function applyData ( $data = NULL ) {
        if (NULL != $data && is_array( $data )) {
            foreach ($data as $propName => $propValue) {
                $this->assignValue( $propName, $propValue );
            }
        } else {
            $this->buildVars();
        }
    }
270622
public function validateEntity($person)
    {
        $this->_validateField($person, 'email');
        $this->_validateField($person, 'username');
        $this->_validateField($person, 'password');

        return parent::validateEntity($person);
    }