Esempio n. 1
0
function goCreateContacts()
{
    $trainees = db::runQuery("select * from process_trainee where processed = '0'  and inerror = '0'");
    if ($trainees) {
        foreach ($trainees as $trains) {
            $traineeBatchID = db::esc($trains['ID']);
            $processgroup = db::esc($trains['processgroupID']);
            //check to make sure this item has been procesed in another thread.
            $dupcheck = db::runQuery("select * from process_trainee where processed = '0' and ID = '{$traineeBatchID}'");
            if (!$dupcheck) {
                //do nothing for now, later date we will add some extra processing steps here when volumes increas heavily.
            } else {
                $contactVars = array('givenName' => $trains['firstname'], 'surname' => $trains['lastname'], 'title' => '', 'emailAddress' => $trains['email'], 'mobilephone' => $trains['mobile'], 'organisation' => $trains['workplace'], 'address1' => $trains['address'], 'city' => $trains['suburb'], 'postcode' => $trains['postcode'], 'USI' => $trains['usi'], 'customField_additionalinfo' => $trains['additionalinfo'], 'customField_processingGroupID' => $trains['processgroupID']);
                db::insertQuery("update process_trainee set processed = '2' where ID = '{$traineeBatchID}'");
                $enroll = axcelerate_save_contact($contactVars);
                ob_start();
                echo "Axcelerate Create Contact\n";
                var_dump($enroll);
                echo "\n\nvars:\n\n";
                var_dump($contactVars);
                $extrans_dump = ob_get_clean();
                dlog($extrans_dump, false, $processgroup);
                dlog("is Error: " . $enroll->ERROR, false, $processgroup);
                dlog("Error Message: : " . $enroll->DETAILS, false, $processgroup);
                if ($enroll->ERROR == 1 || $enroll->ERROR == "1" || $enroll->ERROR == true) {
                    $errorMessage = $enroll->DETAILS;
                    db::insertQuery("update process_trainee set processed = '0', inerror = '1' where ID = '{$traineeBatchID}'");
                    $errorMessage = db::esc($errorMessage);
                    db::insertQuery("update process_group set process_status = '99' and errorMessage = '{$errormessage}' where processgroupID = '{$processgroup}'");
                    markGroupError($processgroup, $errorMessage);
                } else {
                    $contactID = db::esc($enroll->CONTACTID);
                    db::insertQuery("update process_trainee set processed = '1', contactID = '{$contactID}' where ID = '{$traineeBatchID}'");
                    checkEnrolmentsComplete();
                }
            }
        }
    }
    return true;
}
function goEnrolments()
{
    $progroup = db::runQuery("select * from process_group where process_status = '2'");
    if ($progroup) {
        foreach ($progroup as $pgr) {
            $supressInvoiceEmail = "0";
            $generateInvoice = "true";
            $archiveINvoice = "true";
            if ($pgr['campaign_code'] == "") {
                $campaignCode = false;
                $campaignDetails = false;
                $campaignID = 0;
                $campaignName = false;
                $allowOfflinePayments = false;
                $forceOfflinePayments = false;
                $dontInvoiceUser = false;
                $addressToInvoice = false;
                $contactIDtoInvoice = false;
            } else {
                $campaignCode = $pgr['campaign_code'];
                $campaignDetails = getCampaignDetails($campaignCode);
                $campaignID = $campaignDetails['ID'];
                $campaignName = $campaignDetails['campaignName'];
                $allowOfflinePayments = $campaignDetails['allowOfflinePayments'];
                $forceOfflinePayments = $campaignDetails['forceOfflinePayments'];
                $dontInvoiceUser = $campaignDetails['dontInvoiceUser'];
                $addressToInvoice = $campaignDetails['addressToInvoice'];
                $contactIDtoInvoice = $campaignDetails['contactIDtoInvoice'];
                if ($forceOfflinePayments) {
                    $forceOfflinePayments = true;
                } else {
                    $forceOfflinePayments = false;
                }
                if ($contactIDtoInvoice == "") {
                    $contactIDtoInvoice = false;
                }
            }
            $courseID = $pgr['eventID'];
            $courseDetails = getEventDetails($courseID);
            //var_dump($courseDetails);
            if ($campaignDetails) {
                //Course Details
                $courseCostTotal = intval($courseDetails['cost']);
                $totalAttend = $pgr['total_trainee'];
                $courseCostTotal = $courseCostTotal * $totalAttend;
                if ($campaignDetails['discountType'] == 1) {
                    //Percent Discount
                    $courseCostTotal = $courseCostTotal - $courseCostTotal * ("0." . $campaignDetails['discountAmount']);
                    $manualInvoiceEmailPrice = $courseCostTotal;
                    $customPriceOption = false;
                    $sendManualInvoice = false;
                } else {
                    if ($campaignDetails['discountType'] == 2) {
                        //Custom Price Override - Location
                        $customPriceOption = 2;
                        $courseCostTotal = courseCustomPriceLookup($customPriceOption, $courseID, $courseCostTotal, $campaignCode);
                        $manualInvoiceEmailPrice = $courseCostTotal;
                        $dontInvoiceUser = true;
                        $sendManualInvoice = true;
                    } else {
                        if ($campaignDetails['discountType'] == 3) {
                            //Custom Price Override - Course
                            $customPriceOption = 3;
                            $courseCostTotal = courseCustomPriceLookup($customPriceOption, $courseID, $courseCostTotal, $campaignCode);
                            //return errorBackResponse($courseCostTotal." - ".$courseID);
                            $manualInvoiceEmailPrice = $courseCostTotal;
                            $dontInvoiceUser = true;
                            $sendManualInvoice = true;
                        } else {
                            //Dollor Amount Discount
                            $courseCostTotal = $courseCostTotal - $campaignDetails['discountAmount'];
                            $manualInvoiceEmailPrice = $courseCostTotal;
                            $customPriceOption = false;
                            $sendManualInvoice = false;
                        }
                    }
                }
                //return errorBackResponse("Disc Type: ".$campaignDetails['discountType']);
            } else {
                //Course Details
                $courseCostTotal = intval($courseDetails['cost']);
                $totalAttend = $pgr['total_trainee'];
                $courseCostTotal = $courseCostTotal * $totalAttend;
                $manualInvoiceEmailPrice = $courseCostTotal;
            }
            $processgroup = db::esc($pgr['processgroupID']);
            $contactIDtoInvoice = db::esc($contactIDtoInvoice);
            $allowOfflinePayments = db::esc($allowOfflinePayments);
            $forceOfflinePayments = db::esc($forceOfflinePayments);
            $dontInvoiceUser = db::esc($dontInvoiceUser);
            $addressToInvoice = db::esc($addressToInvoice);
            db::insertQuery("update process_group set process_status = '3', primaryContactID = '{$contactIDtoInvoice}', allowOfflinePayments = '{$allowOfflinePayments}', forceOfflinePayments = '{$forceOfflinePayments}', dontInvoiceUser = '******', addressToInvoice = '{$addressToInvoice}', contactIDtoInvoice = '{$contactIDtoInvoice}' where processgroupID = '{$processgroup}'");
            //Create Multi Enrolment
            $trainees = db::runQuery("select * from process_trainee where processgroupID = '{$processgroup}'");
            $primaryContact = "";
            $courseInstanceID = "";
            $processgroup = "";
            $costperperson = $courseDetails['cost'];
            if ($trainees) {
                $contactList = "";
                foreach ($trainees as $trn) {
                    if ($contactList == "") {
                        $contactList = $contactList . $trn['contactID'];
                        $primaryContact = $trn['contactID'];
                        $courseInstanceID = $trn['eventID'];
                        $processgroup = $trn['processgroupID'];
                        $processgroup = $trn['processgroupID'];
                        $costperperson = $trn['cost'];
                    } else {
                        $contactList = $contactList . "," . $trn['contactID'];
                    }
                }
                if ($contactIDtoInvoice != false) {
                    $primaryContact = $contactIDtoInvoice;
                }
                //contact IDS in list   55555,111211,515456
                $supressInvoiceEmail = true;
                //$generateInvoice = true;
                $archiveINvoice = false;
                //$contactInvoiceID = '236951';
                $enrollVars = array('contactID' => $contactList, 'instanceID' => $courseInstanceID, 'invoiceID' => $contactInvoiceID, 'payerID' => $primaryContact, 'type' => 'w');
                $enrollNow = axcelerate_multienroll($enrollVars, $processgroup);
                $contactListarr = explode(",", $contactList);
                $totalCost = 0;
                foreach ($contactListarr as $contact) {
                    $enrollVarsupdate = array('contactID' => $contact, 'instanceID' => $courseInstanceID, 'payerID' => $primaryContact, 'type' => 'w', 'cost' => $costperperson);
                    $enrollNowupdate = axcelerate_multienrollupdate($enrollVarsupdate, $processgroup);
                    var_dump($enrollNowupdate);
                    $totalCost = $totalCost + $costperperson;
                }
                if (isset($enrollNow->error)) {
                    $enrollIsError = true;
                    $trans['message'] = $enrollNow->MESSAGES;
                    dlog("Enrol-Enrolment: Axcelerate returned error: {$processgroup} - " . $trans['message']);
                    markGroupError($processgroup, "");
                    die;
                }
                $groupInvoiceID = "";
                $totalCost = 0;
                foreach ($enrollNow as $student) {
                    $InvoiceID = db::esc($student->INVOICEID);
                    $ContactID = db::esc($student->CONTACTID);
                    $LearnerID = db::esc($student->LEARNERID);
                    $Amount = db::esc($student->AMOUNT);
                    $totalCost = $totalCost + $student->AMOUNT;
                    $groupInvoiceID = $InvoiceID;
                    db::insertQuery("update process_trainee set learnerID = '{$LearnerID}', invoiceID = '{$InvoiceID}' where contactID = '{$ContactID}' and processgroupID = '{$processgroup}'");
                }
                if ($forceOfflinePayments == true) {
                    db::insertQuery("update process_group set GroupInvoiceID = '{$groupInvoiceID}', process_status = '4', totalcost = '{$courseCostTotal}', payment_type = 'offline', primaryContactID = '{$primaryContact}' where processgroupID = '{$processgroup}'");
                } else {
                    db::insertQuery("update process_group set GroupInvoiceID = '{$groupInvoiceID}', process_status = '4', totalcost = '{$courseCostTotal}', primaryContactID = '{$primaryContact}' where processgroupID = '{$processgroup}'");
                }
            }
        }
    }
}