예제 #1
0
 /**
  * Takes the $donor_data array as supplied to $this->giftAidSubmit
  * and adds it into the $package XMLWriter document.
  *
  * $donor_data structure is as follows
  * 'donation_date',
  * 'title',
  * 'first_name',
  * 'last_name',
  * 'house_no',
  * 'postcode', - must be a uk postcode for any uk address
  * 'overseas', - must be true if no postcode provided
  * 'sponsored' - set to true if this money is for a sponsored event
  * 'aggregation' - description of aggregated donations - else leave empty
  * 'amount'
  *
  * @param array $donor_data
  */
 private function buildClaimXml($donor_data)
 {
     $package = new XMLWriter();
     $package->openMemory();
     $package->setIndent(true);
     $package->startElement('Claim');
     $package->writeElement('OrgName', $this->getClaimingOrganisation()->getName());
     $package->writeElement('HMRCref', $this->getClaimingOrganisation()->getHmrcRef());
     $package->startElement('Regulator');
     $package->writeElement('RegName', $this->getClaimingOrganisation()->getRegulator());
     $package->writeElement('RegNo', $this->getClaimingOrganisation()->getRegNo());
     $package->endElement();
     # Regulator
     $package->startElement('Repayment');
     $earliestDate = strtotime(date('Y-m-d'));
     foreach ($donor_data as $d) {
         if (isset($d['donation_date'])) {
             $dDate = strtotime($d['donation_date']);
             $earliestDate = $dDate < $earliestDate ? $dDate : $earliestDate;
         }
         $package->startElement('GAD');
         if (!isset($d['aggregation']) or empty($d['aggregation'])) {
             $package->startElement('Donor');
             $person = new Individual($d['title'], $d['first_name'], $d['last_name'], '', $d['house_no'], $d['postcode'], (bool) $d['overseas']);
             $title = $person->getTitle();
             $fore = $person->getForename();
             $sur = $person->getSurname();
             $house = $person->getHouseNum();
             $postcode = $person->getPostcode();
             $overseas = $person->getIsOverseas();
             if (!empty($title)) {
                 $package->writeElement('Ttl', $title);
             }
             $package->writeElement('Fore', $fore);
             $package->writeElement('Sur', $sur);
             $package->writeElement('House', $house);
             if (!empty($postcode)) {
                 $package->writeElement('Postcode', $postcode);
             } else {
                 $package->writeElement('Overseas', $overseas);
             }
             $package->endElement();
             # Donor
         } elseif (!empty($d['aggregation'])) {
             $package->writeElement('AggDonation', $d['aggregation']);
         }
         if (isset($d['sponsored']) and $d['sponsored'] === true) {
             $package->writeElement('Sponsored', 'yes');
         }
         $package->writeElement('Date', $d['donation_date']);
         $package->writeElement('Total', number_format($d['amount'], 2, '.', ''));
         $package->endElement();
         # GAD
     }
     $package->writeElement('EarliestGAdate', date('Y-m-d', $earliestDate));
     if (!empty($this->gaAdjustment)) {
         $package->writeElement('Adjustment', number_format($this->gaAdjustment, 2, '.', ''));
     }
     $package->endElement();
     # Repayment
     $package->startElement('GASDS');
     $package->writeElement('ConnectedCharities', $this->getClaimingOrganisation()->getHasConnectedCharities() ? 'yes' : 'no');
     foreach ($this->getClaimingOrganisation()->getConnectedCharities() as $cc) {
         $package->startElement('Charity');
         $package->writeElement('Name', $cc->getName());
         $package->writeElement('HMRCref', $cc->getHmrcRef());
         $package->endElement();
         # Charity
     }
     foreach ($this->gasdsYear as $key => $val) {
         $package->startElement('GASDSClaim');
         $package->writeElement('Year', $this->gasdsYear[$key]);
         $package->writeElement('Amount', number_format($this->gasdsAmount[$key], 2, '.', ''));
         $package->endElement();
         # GASDSClaim
     }
     $package->writeElement('CommBldgs', $this->haveCbcd == true ? 'yes' : 'no');
     foreach ($this->cbcdAddr as $key => $val) {
         $package->startElement('Building');
         $package->writeElement('BldgName', $this->cbcdBldg[$key]);
         $package->writeElement('Address', $this->cbcdAddr[$key]);
         $package->writeElement('Postcode', $this->cbcdPoCo[$key]);
         $package->startElement('BldgClaim');
         $package->writeElement('Year', $this->cbcdYear[$key]);
         $package->writeElement('Amount', number_format($this->cbcdAmount[$key], 2, '.', ''));
         $package->endElement();
         # BldgClaim
         $package->endElement();
         # Building
     }
     if (!empty($this->gasdsAdjustment)) {
         $package->writeElement('Adj', number_format($this->gasdsAdjustment, 2, '.', ''));
     }
     $package->endElement();
     # GASDS
     $otherInfo = array();
     if (!empty($this->gasdsAdjustment)) {
         $otherInfo[] = $this->gasdsAdjReason;
     }
     if (!empty($this->gaAdjustment)) {
         $otherInfo[] = $this->gaAdjReason;
     }
     if (count($otherInfo) > 0) {
         $package->writeElement('OtherInfo', implode(' AND ', $otherInfo));
     }
     $package->endElement();
     # Claim
     return $package->outputMemory();
 }