Пример #1
0
 /**
  * Create a new PPI Invoice
  * 
  * @author David Stansfield
  * @public
  * @param int $clientID, int $claimID
  */
 public function action_create_invoice()
 {
     // -- Check that one hasn't been created for this product
     // ------------------------------------------------------
     // -- Set the POST variables
     // -------------------------
     $clientID = \Input::post('Invoice_ClientID');
     $productTypeID = \Input::post('Invoice_Product_Type_ID');
     $clientProductID = \Input::post('Invoice_Client_Product_ID');
     $referenceID = \Input::post('Invoice_ReferenceID');
     $refundMethodID = \Input::post('Refund_Method');
     $correspondence = \Crm\Ppi\Ppi_correspondence::forge((int) $clientID);
     if ($refundMethodID > 0) {
         $refundMethod = \Crm\Ppi\Ppi_class::getRefundMethod($refundMethodID);
     }
     $description = \Input::post('Invoice_Description');
     $qty = \Input::post('Invoice_Qty');
     $charge = \Input::post('Invoice_Charge');
     $fee = \Input::post('Invoice_Fee');
     $vatPc = \Input::post('VAT_Percentage');
     $vat = 0;
     $total = 0;
     $feeTotal = $charge / 100 * $fee;
     $total = $feeTotal * $qty;
     $vat = $total / 100 * $vatPc;
     $total = $total + $vat;
     // -- Create the Invoice
     // ---------------------
     $details = array();
     $details = array('description' => $description . (isset($refundMethod) ? ' | Chosen refund method is ' . $refundMethod : false), 'qty' => $qty, 'charge' => $charge, 'vat_pc' => $vatPc, 'vat_amount' => $vat, 'fee' => $fee, 'total' => $total);
     $invoiceID = \Crm\Invoice\Invoice_class::createInvoice($clientID, $productTypeID, $clientProductID, $referenceID, $details);
     if ($invoiceID > 0) {
         // -- Invoice has been created in the system, now create a Refund Method entry
         // ---------------------------------------------------------------------------
         $refundData = array('claim_id' => $referenceID, 'invoice_id' => $invoiceID, 'method_id' => 0, 'refund_amount' => $charge);
         if (\Crm\Ppi\Ppi_class::createRefundMethod($refundData)) {
             // -- Print the Invoice
             // --------------------
             $extraData = array('date' => date("jS F Y"), 'invoiceDescription' => $description, 'invoiceQuantity' => $qty, 'invoiceCharge' => $charge, 'vatPc' => $vatPc, 'vatAmount' => $vat, 'totalGross' => $feeTotal, 'invoiceCostTotal' => $total, 'claimID' => $referenceID);
             $fileName = 'invoice_' . $clientID . '_' . $invoiceID . '.pdf';
             \Crm\Letter\Letter::forge($clientID, null, $extraData)->writeContent(27)->setOutputFilename($fileName)->printLetter(2)->create();
             // -- Save Correspondence
             // ----------------------
             $correspondence = \Crm\Ppi\Ppi_correspondence::forge((int) $clientID);
             $correspondence->saveNew($referenceID, 10, 28, 0, 'Invoice #' . $invoiceID . ' Created and printed <a href="/uploads/crm/letter/' . $fileName . '" target="_blank">View Letter</a>');
             // -- Save the invoice ID to the claim
             // -----------------------------------
             $claim = \Crm\Ppi\Ppi_claims::forge($referenceID);
             $claim->setInvoiceID($invoiceID);
             $message = $invoiceID;
             $status = 'done';
         } else {
             $message = 'Unable to save Refund Method';
             $status = 'error';
         }
     } else {
         $message = 'Unable to create a new invoice';
         $status = 'error';
     }
     $this->response(array('status' => $status, 'message' => $message));
 }
Пример #2
0
 /**
  * Process the rreturned pack documents
  * @access public
  * @author David
  */
 public function action_pack_in_check($clientID = 0)
 {
     // -- Get the serialized documents info for checking when packs were chased
     // ------------------------------------------------------------------------
     $savedDocuments = array();
     $ppiClient = \Crm\Ppi\Ppi_class::forge((int) $clientID);
     $savedDocuments = $ppiClient->getPackReturnedDocuments();
     $date = date("d/m/Y");
     $documents = array();
     $documents = array('Creditor Information' => array('Completed' => \Input::post('DOCCHECK_Creditor_Information') == 'on' ? 'Yes' : 'No', 'Chase Date' => isset($savedDocuments['Creditor Information']['Chase Date']) && $savedDocuments['Creditor Information']['Chase Date'] != '' && \Input::post('DOCCHECK_Creditor_Information') != 'on' ? $savedDocuments['Creditor Information']['Chase Date'] : (\Input::post('DOCCHECK_Creditor_Information') != 'on' ? $date : ''), 'Notes' => ''), 'LOA' => array('Completed' => \Input::post('DOCCHECK_LOA') == 'on' ? 'Yes' : 'No', 'Chase Date' => isset($savedDocuments['LOA']['Chase Date']) && $savedDocuments['LOA']['Chase Date'] != '' && \Input::post('DOCCHECK_LOA') != 'on' ? $savedDocuments['LOA']['Chase Date'] : (\Input::post('DOCCHECK_LOA') != 'on' ? $date : ''), 'Notes' => ''), 'TaC' => array('Completed' => \Input::post('DOCCHECK_TaC') == 'on' ? 'Yes' : 'No', 'Chase Date' => isset($savedDocuments['TaC']['Chase Date']) && $savedDocuments['TaC']['Chase Date'] != '' && \Input::post('DOCCHECK_TaC') != 'on' ? $savedDocuments['TaC']['Chase Date'] : (\Input::post('DOCCHECK_TaC') != 'on' ? $date : ''), 'Notes' => ''), 'Section F' => array('Completed' => \Input::post('DOCCHECK_Section_F') == 'on' ? 'Yes' : 'No', 'Chase Date' => isset($savedDocuments['Section F']['Chase Date']) && $savedDocuments['Section F']['Chase Date'] != '' && \Input::post('DOCCHECK_Section_F') != 'on' ? $savedDocuments['Section F']['Chase Date'] : (\Input::post('DOCCHECK_Section_F') != 'on' ? $date : ''), 'Notes' => ''));
     if ($ppiClient->pack_completed == 'no') {
         // -- Only process if the pack isn't completed
         // -------------------------------------------
         // -- Save the document information back
         // -------------------------------------
         $ppiClient->savePackReturnedDocuments($documents);
         $correspondence = \Crm\Ppi\Ppi_correspondence::forge((int) $clientID);
         $correspondenceMsg = null;
         // -- If any of the documents have missing infomation and it isn't currently being chased then send out a letter and paperwork, also add a new correspondence
         // ----------------------------------------------------------------------------------------------------------------------------------------------------------
         if (\Input::post('DOCCHECK_Creditor_Information') == 'on' && \Input::post('DOCCHECK_LOA') == 'on' && \Input::post('DOCCHECK_TaC') == 'on' && \Input::post('DOCCHECK_Section_F') == 'on') {
             // -- All paperwork is now complete
             // --------------------------------
             // 1) Mark the Pack as complete
             // 2) Create a correspondence that the pack is complete
             $ppiClient->setPackCompleted();
             $correspondence->saveNew(0, 2, 5, 0, 'Pack Completed');
         } else {
             $letterHead = array();
             $letterBlank = array();
             $missing = array();
             $referralInfo = \Crm\Referrals\Referrals_class::forge((int) $correspondence->referral_id);
             $creditors = $referralInfo->loadData('creditors');
             $letterConfig = \Crm\Ppi\Ppi_class::loadLettersList((int) $ppiClient->company_id);
             unset($referralInfo);
             // -- Missing Creditor Information
             // -------------------------------
             if (\Input::post('DOCCHECK_Creditor_Information') != 'on' && $savedDocuments['Creditor Information']['Chase Date'] == '') {
                 $correspondenceMsg .= 'Pack Incomplete. Missing information found on the Creditor Information Section.' . "\r\n";
                 $letterHead[] = array('id' => $letterConfig['missing_loa'], 'qty' => 1, 'tray_id' => 2);
                 $letterBlank[] = array('id' => $letterConfig['ppi_form_of_authority'], 'qty' => count($creditors) > 0 ? count($creditors) : 3, 'tray_id' => 1);
                 $missing[] = '<li>Creditor name / Account Number</li>';
             }
             // -- Missing LOA
             // --------------
             if (\Input::post('DOCCHECK_LOA') != 'on' && $savedDocuments['LOA']['Chase Date'] == '') {
                 $correspondenceMsg .= 'Pack Incomplete. Missing information found on the LOA Section.' . "\r\n";
                 $letterHead[] = array('id' => $letterConfig['missing_loa'], 'qty' => 1, 'tray_id' => 2);
                 $letterBlank[] = array('id' => $letterConfig['ppi_form_of_authority'], 'qty' => count($creditors) > 0 ? count($creditors) : 3, 'tray_id' => 1);
                 $missing[] = '<li>Signed Form of Authority</li>';
             }
             // -- Missing Terms and Conditions
             // -------------------------------
             if (\Input::post('DOCCHECK_TaC') != 'on' && $savedDocuments['TaC']['Chase Date'] == '') {
                 $correspondenceMsg .= 'Pack Incomplete. Missing information found on the Terms and Conditions Section.' . "\r\n";
                 $letterHead[] = array('id' => $letterConfig['missing_tac'], 'qty' => 1, 'tray_id' => 2);
                 $letterBlank[] = array('id' => $letterConfig['terms_and_conditions_GAB'], 'qty' => 1, 'tray_id' => 1);
                 $missing[] = '<li>Signed Terms and Conditions</li>';
             }
             // -- Missing Section "F"
             // ----------------------
             if (\Input::post('DOCCHECK_Section_F') != 'on' && $savedDocuments['Section F']['Chase Date'] == '') {
                 $correspondenceMsg .= 'Pack Incomplete. Missing information Section F Isn\'t filled in.' . "\r\n";
                 $missing[] = '<li>Signed Section F</li>';
                 $printSectionF = true;
             }
         }
     }
     if (!is_null($correspondenceMsg)) {
         // -- Pack is found to be incomplete. Set correspondence and send letter out
         // -------------------------------------------------------------------------
         $correspondence->saveNew(0, 2, 2, 0, $correspondenceMsg);
         if ($ppiClient->company_id == 1) {
             $timeSlot = 1;
         } else {
             if ($ppiClient->company_id == 3) {
                 $timeSlot = 2;
             }
         }
         // -- Persolvo Letters
         if (count($missing) > 1) {
             unset($letterHead);
             $letterHead[] = array('id' => $letterConfig['missing_several_documents'], 'qty' => 1, 'tray_id' => 2);
             $extraData = array();
             $freeText = '';
             foreach ($missing as $missingText) {
                 $freeText .= $missingText;
             }
             $extraData = array('freeText' => $freeText);
         }
         #if(count($letterHead) > 0)
         #  \Crm\Letter\Pack::forge((int)$clientID,null,$letterHead)->setOutputFilename('ppi_missing_info_pack_coverletter_' . date("dmy") . '_' .(int)$clientID.'.pdf')->printLetter(2, 40)->timeSlot($timeSlot)->create();
         \Crm\Letter\Letter::forge($clientID, null, $extraData)->writeContent($letterHead[0]['id'])->setOutputFilename('ppi_missing_info_pack_coverletter_' . date("dmy") . '_' . (int) $clientID . '.pdf')->printLetter($letterHead[0]['tray_id'])->timeSlot($timeSlot)->create();
         if (count($letterBlank) > 0) {
             \Crm\Letter\Pack::forge((int) $clientID, null, $letterBlank)->setOutputFilename('ppi_missing_info_pack_' . date("dmy") . '_' . (int) $clientID . '.pdf')->printLetter(1, 40)->timeSlot($timeSlot)->create();
         }
         if ($printSectionF == true) {
             \Printmanager\Queue::add(DOCROOT . 'uploads/crm/forms/section_f_form.pdf', $timeSlot == 1 ? date('Y-m-d 14:00:00') : date('Y-m-d 20:30:00'), 1);
         }
         #\Printmanager\Queue::add(DOCROOT . 'uploads/crm/forms/section_f_form.pdf', ( (int)date('H') < 14 ) ? date('Y-m-d 14:00:00') : date('Y-m-d 20:30:00'), 1);
         $correspondence->saveNew(0, 2, 3, 0, 'Letter Sent to Client');
     }
     // -- If all the documents have been completed, then set the Pack Completed field as Yes
     // -------------------------------------------------------------------------------------
     Response::redirect('crm/view_client/' . $clientID . '/');
 }