示例#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()
 }
示例#2
0
 /**
   Generate the message
   @param $val the value returned by the object's select_condition()
   @param $ref a transaction reference (emp-lane-trans)
   @param $reprint boolean
   @return [string] message to print on receipt
 */
 public function message($val, $ref, $reprint = False)
 {
     global $CORE_LOCAL;
     if ($val == 0) {
         return '';
     }
     $lineStart = "";
     $lineEnd = "\n";
     $conn = CoopCredLib::ccDataConnect();
     if ($conn === False) {
         return "Error: ccDataConnect() failed." . $lineEnd;
     }
     $chgName = ReceiptLib::getChgName();
     $dateTimeStamp = time();
     $date = ReceiptLib::build_time($dateTimeStamp);
     $itemSeparator = '';
     for ($i = 1; $i <= 7; $i++) {
         $itemSeparator .= $lineEnd;
     }
     $cutPaper = chr(27) . chr(105) . chr(27) . chr(33) . chr(5);
     $projectName = _('Coop Cred');
     $projectUC = _('COOP CRED');
     $slip = '';
     $tu = $CORE_LOCAL->get('CCredTendersUsed');
     foreach ($tu as $tTender => $tProgramID) {
         $programCode = "CCred{$tProgramID}";
         $programName = $CORE_LOCAL->get("{$programCode}programName");
         $subs = CoopCredLib::getCCredSubtotals($tTender, $conn, $programCode, 'localtranstoday', $ref);
         if ($subs !== True) {
             return "Error: Coop Cred Program " . $tProgramID . " subtotals.";
         }
         $labels["{$programCode}"] = array("{$projectUC} '{$programName}' ACCOUNT\n", "Tender:{$tTender} Debit Amount:", "I ACKNOWLEDGE THE ABOVE DEBIT\n", "TO MY {$projectUC} '{$programName}' ACCOUNT\n");
         $slip .= $itemSeparator . $cutPaper . "\n" . ReceiptLib::centerString("S T O R E   C O P Y") . "\n" . ReceiptLib::centerString("................................................") . "\n\n" . $labels["{$programCode}"][0] . "Name: " . trim($chgName) . "\n" . "Member Number: " . trim($CORE_LOCAL->get("memberID")) . "\n" . "Date: " . $date . "\n" . "REFERENCE #: " . $ref . "\n" . $labels["{$programCode}"][1] . " \$" . number_format(-1 * $CORE_LOCAL->get("{$programCode}chargeTotal"), 2) . "\n" . $labels["{$programCode}"][2] . $labels["{$programCode}"][3] . "Member Sign Below\n\n\n" . "X____________________________________________\n" . $CORE_LOCAL->get("fname") . " " . $CORE_LOCAL->get("lname") . "\n\n" . ReceiptLib::centerString(".................................................") . "\n\n";
         // each tender
     }
     return $slip;
 }
示例#3
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;
 }
示例#4
0
 /**
   Generate the message
   @param $val the value returned by the object's select_condition()
   @param $ref a transaction reference (emp-lane-trans)
   @param $reprint boolean
   @return [string] message to print on receipt
 */
 public function message($val, $ref, $reprint = False)
 {
     global $CORE_LOCAL;
     if ($val == 0) {
         return '';
     }
     $lineStart = "";
     $lineEnd = "\n";
     $conn = CoopCredLib::ccDataConnect();
     if ($conn === False) {
         return "Error: ccDataConnect() failed." . $lineEnd;
     }
     $dateTimeStamp = time();
     $date = ReceiptLib::build_time($dateTimeStamp);
     $projectName = _('Coop Cred');
     $itemSeparator = '';
     for ($i = 1; $i <= 2; $i++) {
         $itemSeparator .= $lineEnd;
     }
     $slip = $itemSeparator;
     $programsReported = array();
     $tu = $CORE_LOCAL->get('CCredTendersUsed');
     if (is_array($tu)) {
         foreach ($tu as $tTender => $tProgramID) {
             if (in_array($tProgramID, $programsReported)) {
                 continue;
             } else {
                 $programsReported[] = $tProgramID;
             }
             $programCode = "CCred{$tProgramID}";
             $programName = $CORE_LOCAL->get("{$programCode}programName");
             $subs = CoopCredLib::getCCredSubtotals($tTender, $conn, $programCode, 'localtranstoday', $ref);
             if ($subs !== True) {
                 return "Error: Coop Cred Program " . $tProgramID . " subtotals.";
             }
             $acb = $CORE_LOCAL->get("{$programCode}availBal") != '' ? $CORE_LOCAL->get("{$programCode}availBal") : _("Balance not available.");
             $slip .= sprintf("%s: %s %s: \$ %s%s", $projectName, $programName, _("Remaining"), $acb, $lineEnd . $lineEnd);
             // each tender
         }
     }
     $du = $CORE_LOCAL->get('CCredDepartmentsUsed');
     if (is_array($du)) {
         foreach ($du as $dDepartment => $dProgramID) {
             if (in_array($dProgramID, $programsReported)) {
                 continue;
             } else {
                 $programsReported[] = $dProgramID;
             }
             $programCode = "CCred{$dProgramID}";
             $programName = $CORE_LOCAL->get("{$programCode}programName");
             $pcTenderType = $CORE_LOCAL->get("{$programCode}tenderType");
             $subs = CoopCredLib::getCCredSubtotals($pcTenderType, $conn, $programCode, 'localtranstoday', $ref);
             if ($subs !== True) {
                 return "Error: Coop Cred Program " . $dProgramID . " subtotals.";
             }
             $acb = $CORE_LOCAL->get("{$programCode}availBal") != '' ? $CORE_LOCAL->get("{$programCode}availBal") : _("Balance not available.");
             $slip .= sprintf("%s: %s %s: \$ %s%s", $projectName, $programName, _("Remaining"), $acb, $lineEnd . $lineEnd);
             // each department
         }
     }
     return $slip;
 }
示例#5
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;
 }