예제 #1
0
파일: index.php 프로젝트: ClixLtd/pccupload
 /**
  * Create Claims from the Creditors
  * 
  * @author David Stansfield
  * @access public
  */
 public function action_create_claims($clientID = 0)
 {
     // -- Set Client ID
     // ----------------
     $creditors = array();
     $claim = array();
     $claim = \Input::post('claim');
     $ppiClient = \Crm\Ppi\Ppi_class::forge($clientID);
     $ppiClientID = $ppiClient->id;
     $correspondence = \Crm\Ppi\Ppi_correspondence::forge((int) $clientID);
     if (count($claim) > 0) {
         $creditors[0] = $claim;
     } else {
         // -- Get the creditors from the referrals data
         // --------------------------------------------
         $referral = \Crm\Referrals\Referrals_class::forge($ppiClient->referral_id);
         $creditors = array();
         $creditors = $referral->loadData('creditors');
     }
     if (count($creditors) > 0) {
         foreach ($creditors as $key => $creditorInfo) {
             //-- Create the claim
             // ------------------
             $claimID = \Crm\Ppi\Ppi_claims::createNewClaim($ppiClientID, $creditorInfo);
             if ($claimID > 0) {
                 \log::write('Action', 'Claim created ' . $claimID);
                 // -- Created Claim. Now create claim letter
                 // -----------------------------------------
                 #$claim = \Crm\Ppi\Ppi_claims::forge($claimID);
                 #$extraData = array('accountReference' => $claim->account_number,
                 #                   'creditorAddress' => $claim->getCreditorDetails()->address('<br />'));
                 // -- Send the letter out
                 // ----------------------
                 #\Crm\Letter\Letter::forge($clientID, null, $extraData)->writeContent(8)->setOutputFilename('claim_letter_' . $clientID . '_' . $claimID . '.pdf')->printLetter(2)->create();
                 // -- Add to correspondence for client and claim - Sets it to Claim, Created
                 // -------------------------------------------------------------------------
                 $correspondence->saveNew($claimID, 3, 36, 0, 'Claim Created. Claim ID: ' . $claimID);
                 $this->response(array('status' => 'SUCCESS'));
             } else {
                 // -- Failed to create claim for that creditor
                 // -------------------------------------------
                 \Log::write('Error', 'Failed to create Claim for Client: ' . $ppiClientID . ' Creditor: ' . $creditorInfo['creditor_choice']);
             }
         }
     }
     //Response::redirect('crm/view_client/'.$clientID.'/');
 }