Example #1
0
 /**
   Check for errors
   @return True or an error message string
 */
 public function errorCheck()
 {
     global $CORE_LOCAL;
     $this->conn = CoopCredLib::ccDataConnect();
     if ($this->conn === False) {
         return "Error: ccDataConnect() failed.";
     }
     $programOK = CoopCredLib::programOK($this->tender_code, $this->conn);
     if ($programOK !== True) {
         return DisplayLib::boxMsg("{$programOK}");
     }
     $subtotals = CoopCredLib::getCCredSubtotals($this->tender_code, $this->conn);
     if ($subtotals !== True) {
         return DisplayLib::boxMsg("{$subtotals}");
     }
     $pc = $CORE_LOCAL->get("CCredProgramCode");
     //$pc = $CORE_LOCAL->get("programCode");
     /* For Refunding the total without entering the exact amount
      *  i.e. with QA alone.
      */
     if ($this->amount == '' && $this->DefaultTotal() < 0) {
         $this->amount = $this->DefaultTotal();
     }
     /* No Available Balance.
      */
     if ($CORE_LOCAL->get("{$pc}availBal") < 0) {
         return DisplayLib::boxMsg(_("Member") . " #" . $CORE_LOCAL->get("memberID") . ' ' . _("does not have enough Coop Cred in ") . '<b>' . $CORE_LOCAL->get("{$pc}programName") . '</b>' . _(" to cover this purchase."));
     }
     /* Tender more than Available Balance
      * the amount remaining less the amount of this type already tendered
      * in the current transaction.
      * I think availBal already includes memChargeTotal.
      */
     if (abs($CORE_LOCAL->get("{$pc}memChargeTotal")) + $this->amount >= $CORE_LOCAL->get("{$pc}availBal") + 0.005) {
         $memChargeCommitted = $CORE_LOCAL->get("{$pc}availBal") + $CORE_LOCAL->get("{$pc}memChargeTotal");
         return DisplayLib::xboxMsg(_("The amount of Coop Cred you have in ") . '<b>' . $CORE_LOCAL->get("{$pc}programName") . '</b>' . _(" is only \$") . number_format($memChargeCommitted, 2) . '.');
     }
     /* Tender more than Amount Due.
      */
     if (MiscLib::truncate2($CORE_LOCAL->get("amtdue")) < MiscLib::truncate2($this->amount)) {
         return DisplayLib::xboxMsg(_("The amount of Coop Cred tendered may not exceed the Amount Due."));
     }
     /* Add the tender to those used in this transaction.
      */
     if ($CORE_LOCAL->get('CCredTendersUsed') == '') {
         $CORE_LOCAL->set('CCredTendersUsed', array("{$this->tender_code}" => $CORE_LOCAL->get("CCredProgramID")));
     } else {
         $tu = $CORE_LOCAL->get('CCredTendersUsed');
         if (!array_key_exists("{$this->tender_code}", $tu)) {
             $tu["{$this->tender_code}"] = $CORE_LOCAL->get("CCredProgramID");
             $CORE_LOCAL->set('CCredTendersUsed', $tu);
         }
     }
     return true;
     // errorCheck()
 }
Example #2
0
 /**
   Return a message containing Available Balance
   after the just-completed transaction
   for each Program the member belongs to.
   @param $str [string] from the custReceiptMessage table record.
     format: "AAA BBB \d" where AAA will sort to the right sequence
             and \d is the CCredPrograms.programID
     I don't remember why three fields. AAA \d may be enough.
   @return [string] message about Available Balance for each Program
   the member belongs to.
 */
 public function message($str)
 {
     global $CORE_LOCAL;
     $lineStart = "";
     $lineEnd = "\n";
     $msg = explode(' ', $str);
     // 9Oct2014 Why [2]? Wouldn't [1] be enough?
     if (!isset($msg[2]) || !preg_match('/^\\d+$/', $msg[2])) {
         return "Error: No program id in {$str}{$lineEnd}";
     }
     $programID = $msg[2];
     if (!in_array('CoopCred', $CORE_LOCAL->get('PluginList'))) {
         $ret = "{$lineStart}" . _("Coop Cred is not currently in use at this co-op.") . "{$lineEnd}";
         return $ret;
     }
     $conn = CoopCredLib::ccDataConnect();
     if ($conn === False) {
         return "Error: ccDataConnect() failed." . $lineEnd;
     }
     $ccQ = "SELECT p.programID, p.programName, p.tenderType,\n            p.active, p.startDate, p.endDate,\n            p.bankID, p.creditOK, p.inputOK, p.transferOK,\n            m.creditBalance, m.creditLimit, m.creditOK, m.inputOK,\n                m.transferOK, m.isBank\n                ,(m.creditLimit - m.creditBalance) as availCreditBalance\n                ,c.FirstNAme, c.LastName\n            FROM CCredMemberships m\n            JOIN CCredPrograms p ON p.programID = m.programID\n            JOIN {$CORE_LOCAL->get('pDatabase')}.custdata c\n                ON m.cardNo = c.CardNo\n                WHERE m.cardNo =" . $CORE_LOCAL->get("memberID") . " AND m.programID={$programID}\n                 AND c.personNum=1";
     $ccS = $conn->prepare_statement("{$ccQ}");
     if ($ccS === False) {
         return "Statement prep for Program {$programID} failed.{$lineEnd}";
     }
     $args = array();
     $ccR = $conn->exec_statement($ccS, $args);
     if ($ccR === False) {
         return "Query for Program {$programID} failed.{$lineEnd}";
     }
     if ($conn->num_rows($ccR) == 0) {
         $ret = "Member " . $CORE_LOCAL->get("memberID") . _(" is not registered for Coop Cred Program {$programID}.") . "{$lineEnd}";
         return $ret;
     }
     /* For each Coop Cred Program the member is in.
      */
     while ($row = $conn->fetch_array($ccR)) {
         $programOK = CoopCredLib::programOK($row['tenderType'], $conn);
         if ($programOK === True) {
             $subs = CoopCredLib::getCCredSubtotals($row['tenderType'], $conn);
             if ($subs !== True) {
                 return "Error: Coop Cred Program " . $programID . " subtotals.";
             }
             $projectName = 'Coop Cred';
             $pcode = 'CCred' . $programID;
             $pname = $CORE_LOCAL->get("{$pcode}ProgramName");
             $acb = $CORE_LOCAL->get("{$pcode}availBal") != '' ? $CORE_LOCAL->get("{$pcode}availBal") : _("Balance not available.");
             $ret = sprintf("%s: %s %s: \$ %s%s", $projectName, $pname, _("Available"), $acb, $lineEnd);
         } else {
             $ret = $programOK . $lineEnd;
         }
     }
     return $ret;
 }
 public function handle($deptID, $amount, $json)
 {
     global $CORE_LOCAL;
     $realDeptID = $deptID / 10;
     $programOK = CoopCredLib::programOK($realDeptID);
     if ($programOK !== True) {
         /* If there's a problem can boxMsg2 only accept CL?
          */
         $boxMsg = $programOK . "<br /><span style='font-size:0.8em;'>Press [clear]</span>";
     } else {
         $programCode = $CORE_LOCAL->get("CCredProgramCode");
         if ($programCode == '') {
             $programCode = 'empty';
         }
         $programName = $CORE_LOCAL->get("{$programCode}programName");
         CoopCredLib::addDepartmentUsed($realDeptID, $CORE_LOCAL->get("CCredProgramID"));
         $boxMsg = "<b>Coop Cred Input to<br />'{$programName}'</b><br />\$" . number_format($amount, 2) . "<br />Remember to " . "keep your receipt.<br />" . "<span style='font-size:0.8em;'>[enter] to continue<br />[clear] to cancel</span>";
     }
     if ($CORE_LOCAL->get('msgrepeat') == 0) {
         $CORE_LOCAL->set("boxMsg", $boxMsg);
         $json['main_frame'] = MiscLib::base_url() . 'gui-modules/boxMsg2.php?quiet=1';
     }
     return $json;
 }
Example #4
0
 function parse($str)
 {
     global $CORE_LOCAL;
     $ret = $this->default_json();
     $pStyle = "<p style='font-weight:bold; text-align:center; margin: 0em 0em 0em -1.0em;'>";
     if (!in_array('CoopCred', $CORE_LOCAL->get('PluginList'))) {
         $message = "{$pStyle}" . _("Coop Cred is not currently in use at this co-op.") . "</p>";
         $ret['output'] = DisplayLib::boxMsg("{$message}", "", True);
         return $ret;
     }
     $conn = CoopCredLib::ccDataConnect();
     if ($conn === False) {
         return "Error: ccDataConnect() failed.";
     }
     $ccQ = "SELECT p.programID AS ppID, p.programName, p.tenderType,\n            p.active, p.startDate, p.endDate,\n            p.bankID, p.creditOK, p.inputOK, p.transferOK,\n            m.creditBalance, m.creditLimit, m.creditOK, m.inputOK,\n                m.transferOK, m.isBank\n                ,(m.creditLimit - m.creditBalance) as availCreditBalance\n                ,c.FirstNAme, c.LastName\n            FROM CCredMemberships m\n            JOIN CCredPrograms p\n                ON p.programID = m.programID\n            JOIN {$CORE_LOCAL->get('pDatabase')}.custdata c\n                ON m.cardNo = c.CardNo\n            WHERE m.cardNo =" . $CORE_LOCAL->get("memberID") . " AND c.personNum=1 " . "ORDER BY ppID";
     $ccS = $conn->prepare_statement("{$ccQ}");
     if ($ccS === False) {
         $ret['output'] = DisplayLib::boxMsg("<p>Prep Failed: {$ccQ}</p>", "", True);
         return $ret;
     }
     $args = array();
     $ccR = $conn->exec_statement($ccS, $args);
     if ($ccR === False) {
         $ret['output'] = DisplayLib::boxMsg("<p>Query Failed: {$ccQ}</p>", "", True);
         return $ret;
     }
     if ($conn->num_rows($ccR) == 0) {
         $message = "{$pStyle}Member " . $CORE_LOCAL->get("memberID") . _(" is not registered for any Coop Cred Programs.") . "</p>";
         $ret['output'] = DisplayLib::boxMsg("{$message}", "", True);
         return $ret;
     }
     $pStyle2 = "style='" . "font-weight:bold; " . "text-align:center; " . "margin: 0em 0em 0em -1.0em; " . "'";
     $message = "<p {$pStyle2}>";
     $message .= _("Member") . " #" . $CORE_LOCAL->get("memberID");
     $message .= "<br />" . _("Can spend these amounts of Coop Cred:");
     $message .= "</p>";
     $bStyle3 = "style='" . "margin: 0.25em 0em 0em -3.0em; " . "'";
     $message .= "<div {$bStyle3}>";
     $tableStyle1 = "style='" . "width: 16em; " . "'";
     $rowStyle = "style='vertical-align:top;' ";
     $keyStyle = "style='font-size:0.8em;' ";
     $nameStyle = "style='font-size:0.8em;' ";
     $narrowAmountStyle = "style='text-align:right; font-size:1.2em;' ";
     $wideAmountStyle = "style='text-align:right; font-size:1.1em;' ";
     $notOkStyle = "style='font-size:0.8em;' ";
     $noteStyle = "style='font-size:0.7em;' ";
     $message .= "<table {$tableStyle1} cellpadding=2 cellspacing=0 border=0>";
     while ($row = $conn->fetch_array($ccR)) {
         $programOK = CoopCredLib::programOK($row['tenderType'], $conn);
         if ($programOK === True) {
             $programCode = 'CCred' . $CORE_LOCAL->get("CCredProgramID");
             $subtotals = CoopCredLib::getCCredSubtotals($row['tenderType'], $conn);
             $tenderKeyCap = $CORE_LOCAL->get("{$programCode}tenderKeyCap") != "" ? $CORE_LOCAL->get("{$programCode}tenderKeyCap") : 'CCr' . $CORE_LOCAL->get("CCredProgramID");
             $programBalance = $CORE_LOCAL->get("{$programCode}availBal") ? $CORE_LOCAL->get("{$programCode}availBal") : $CORE_LOCAL->get("{$programCode}availCreditBalance");
             $programBalanceString = sprintf("\$%s", number_format($programBalance, 2));
             $amountStyle = strlen($programBalanceString) <= 9 ? $narrowAmountStyle : $wideAmountStyle;
             $message .= sprintf("%s%s%s%s%s%s%s", "<tr {$rowStyle}><td {$keyStyle}>", "[{$tenderKeyCap}]", "</td><td {$nameStyle}>", $CORE_LOCAL->get("{$programCode}programName"), "</td><td {$amountStyle}>", $programBalanceString, "</td></tr>");
         } else {
             $message .= "<tr><td colspan=99 {$notOkStyle}>" . $programOK . "</td></tr>";
         }
     }
     $note = _("The amounts reflect any tenders of, or inputs to, " . "Coop Cred in the current transaction.");
     $message .= "<tr><td colspan=99 {$noteStyle}>" . $note . "</td></tr>";
     /* Want: self, mode=Print
      */
     $printButton = "<button type='submit' value='" . $CORE_LOCAL->get('memberID') . "' onClick='' " . " title='Not implemented yet' " . ">" . "Print" . "</button>";
     $message .= "<tr><td colspan=99 >" . $printButton . "</td></tr>";
     $message .= "</table>";
     $message .= "</div>";
     $ret['output'] = DisplayLib::boxMsg("{$message}", "", True);
     return $ret;
 }
Example #5
0
 /**
   Assign store-specific alternate member message line
   @param $store code for the coop
   @param $member CardNo from custdata
   @param $personNumber personNum from custdata
   @param $row a record from custdata
   @param $chargeOk whether member can store-charge purchases
 */
 public static function setAltMemMsg($store, $member, $personNumber, $row, $chargeOk)
 {
     if ($store == 'WEFC_Toronto') {
         /* Doesn't quite allow for StoreCharge/PrePay for regular members
          * either instead of or in addition to CoopCred
          */
         if (isset($row['blueLine'])) {
             $memMsg = $row['blueLine'];
         } else {
             $memMsg = '#' . $member;
         }
         if ($member == CoreLocal::get('defaultNonMem')) {
             CoreLocal::set("memMsg", $memMsg);
             return;
         }
         if ($member < 99000) {
             if (in_array('CoopCred', CoreLocal::get('PluginList'))) {
                 $conn = CoopCredLib::ccDataConnect();
                 if ($conn !== False) {
                     $ccQ = "SELECT p.programID AS ppID, p.programName, p.tenderType,\n                        p.active, p.startDate, p.endDate,\n                        p.bankID, p.creditOK, p.inputOK, p.transferOK,\n                        m.creditBalance, m.creditLimit, m.creditOK, m.inputOK,\n                            m.transferOK, m.isBank\n                            ,(m.creditLimit - m.creditBalance) as availCreditBalance\n                        FROM CCredMemberships m\n                        JOIN CCredPrograms p\n                            ON p.programID = m.programID\n                            WHERE m.cardNo =?" . " ORDER BY ppID";
                     $ccS = $conn->prepare_statement("{$ccQ}");
                     if ($ccS === False) {
                         CoreLocal::set("memMsg", $memMsg . "Prep failed");
                         return;
                     }
                     $args = array();
                     $args[] = $member;
                     $ccR = $conn->exec_statement($ccS, $args);
                     if ($ccR === False) {
                         CoreLocal::set("memMsg", $memMsg . "Query failed");
                         return;
                     }
                     if ($conn->num_rows($ccR) == 0) {
                         CoreLocal::set("memMsg", $memMsg);
                         return;
                     }
                     $message = "";
                     while ($row = $conn->fetch_array($ccR)) {
                         $programOK = CoopCredLib::programOK($row['tenderType'], $conn);
                         if ($programOK === True) {
                             $programCode = 'CCred' . CoreLocal::get("CCredProgramID");
                             $tenderKeyCap = CoreLocal::get("{$programCode}tenderKeyCap") != "" ? CoreLocal::get("{$programCode}tenderKeyCap") : 'CCr' . CoreLocal::get("CCredProgramID");
                             $programBalance = CoreLocal::get("{$programCode}availBal") ? CoreLocal::get("{$programCode}availBal") : CoreLocal::get("{$programCode}availCreditBalance");
                             $message .= " {$tenderKeyCap}: " . number_format($programBalance, 2);
                         } else {
                             $message .= $row['tenderType'] . " not OK";
                         }
                     }
                     if ($message != "") {
                         CoreLocal::set("memMsg", $memMsg . "{$message}");
                         return;
                     }
                 }
             }
             if ($chargeOk == 1) {
                 $conn = Database::pDataConnect();
                 $query = "SELECT ChargeLimit AS CLimit\n                    FROM custdata\n                    WHERE personNum=1 AND CardNo = {$member}";
                 $table_def = $conn->table_definition('custdata');
                 // 3Jan14 schema may not have been updated
                 if (!isset($table_def['ChargeLimit'])) {
                     $query = str_replace('ChargeLimit', 'MemDiscountLimit', $query);
                 }
                 $result = $conn->query($query);
                 $num_rows = $conn->num_rows($result);
                 if ($num_rows > 0) {
                     $row2 = $conn->fetch_array($result);
                 } else {
                     $row2 = array();
                 }
                 if (isset($row2['CLimit'])) {
                     $limit = 1.0 * $row2['CLimit'];
                 } else {
                     $limit = 0.0;
                 }
                 // Prepay
                 if ($limit == 0.0) {
                     CoreLocal::set("memMsg", $memMsg . _(' : Pre Pay: $') . number_format((double) CoreLocal::get("availBal") * 1, 2));
                     // Store Charge
                 } else {
                     CoreLocal::set("memMsg", $memMsg . _(' : Store Charge: $') . number_format((double) CoreLocal::get("availBal") * 1, 2));
                 }
             }
             // Intra-coop transfer
         } else {
             CoreLocal::set("memMsg", $memMsg);
             CoreLocal::set("memMsg", $memMsg . _(' : Intra Coop spent: $') . number_format((double) CoreLocal::get("balance") * 1, 2));
         }
         // WEFC_Toronto
     }
     //return $ret;
 }