示例#1
0
 public function preprocess()
 {
     global $FANNIE_OP_DB, $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors[] = "The Coop Cred plugin is not enabled.";
         return False;
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         $this->errors[] = "The Coop Cred database is not assigned in the " . "Coop Cred plugin configuration.";
         return False;
     }
     $this->cardNo = (int) FormLib::get('memNum', 0);
     $this->programID = (int) FormLib::get('programID', 0);
     $ccpModel = new CCredProgramsModel($dbc);
     $ccpModel->programID($this->programID);
     $prog = array_pop($ccpModel->find());
     if ($prog != null) {
         $this->programName = $prog->programName();
         $this->programBankID = $prog->bankID();
     } else {
         $this->errors[] = "Error: Program ID {$this->programID} is not known.";
         return False;
     }
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $cdModel = new CustdataModel($dbc);
     $cdModel->CardNo($this->cardNo);
     $cdModel->personNum(1);
     $mem = array_pop($cdModel->find());
     if ($mem != null) {
         $this->memberFullName = $mem->FirstName() . " " . $mem->LastName();
     } else {
         $noop = 1;
         $this->errors[] = "Error: Member {$this->cardNo} is not known.";
         return False;
     }
     /* 25Mar2015 Under bootstrap the non-sortable format doesn't really work.
      */
     $this->sortable = True;
     return parent::preprocess();
 }
示例#2
0
 function preprocess()
 {
     global $FANNIE_CORRECTION_CASHIER, $FANNIE_CORRECTION_LANE, $FANNIE_CORRECTION_DEPT;
     global $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     if (isset($FANNIE_CORRECTION_CASHIER)) {
         $this->CORRECTION_CASHIER = $FANNIE_CORRECTION_CASHIER;
     }
     if (isset($FANNIE_CORRECTION_LANE)) {
         $this->CORRECTION_LANE = $FANNIE_CORRECTION_LANE;
     }
     if (isset($FANNIE_CORRECTION_DEPT)) {
         $this->CORRECTION_DEPT = $FANNIE_CORRECTION_DEPT;
     }
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors .= "Error: Coop Cred Plugin is not enabled.";
         return True;
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         $this->errors .= "Error: Coop Cred Database not named in Plugin Settings.";
         return True;
     }
     $OP = $FANNIE_OP_DB . $dbc->sep();
     if (FormLib::get_form_value('programID', False) !== False) {
         $this->programID = FormLib::get_form_value('programID');
     } else {
         $this->errors .= "<em>" . _("Error: ") . _("Program ID not supplied.") . "</em>" . "";
         return True;
     }
     if (FormLib::get_form_value('programID') == "0") {
         $backLabel = _("Return to Member Editor");
         $this->errors .= "<em>" . _("Warning: ") . _("The Member does not yet belong to a Program.") . "<br />" . _("Please add him/her to a Program, Save, and Edit again to do the Transfer.") . "</em>" . "<br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>" . "";
         return True;
     }
     $ccpModel = new CCredProgramsModel($dbc);
     $ccpModel->programID($this->programID);
     $inputOK = null;
     $prog = array_pop($ccpModel->find());
     if ($prog == null) {
         $this->errors .= "<em>Error: Program ID {$this->programID} is not known.</em>";
         return True;
     }
     $inputOK = $prog->inputOK();
     $this->programPaymentDepartment = $prog->paymentDepartment();
     $this->dept = $prog->paymentDepartment();
     $this->programName = $prog->programName();
     $this->programBankNumber = $prog->bankID();
     /* To use while choosing dept is still part of the form.
      * It isn't, in Input or Transfer but maybe in another Tool?
      */
     $this->depts[$this->dept] = $this->programName;
     /* 16Dec2014 This is not tickable on the form yet.
      */
     $this->negativeBalanceOK = FormLib::get_form_value('negativeBalanceOK', False);
     foreach ($_REQUEST as $name => $value) {
         $item = "{$name}={$value}";
         if (!in_array("{$item}", $this->hiddenSearch) && substr($name, 0, 6) != "submit") {
             $this->hiddenSearch[] = "{$item}";
         }
     }
     if (FormLib::get_form_value('memEDIT', False) !== False) {
         $this->memberBeingEdited = FormLib::get_form_value('memEDIT');
     }
     if (FormLib::get_form_value('submit1', False) !== False) {
         $this->mode = 'confirm';
     } elseif (FormLib::get_form_value('submit2', False) !== False) {
         $this->mode = 'finish';
     }
     /* If the transfer values form is to be displayed
      */
     if ($this->mode == 'init') {
         $memNum = FormLib::get_form_value('memIN');
         if ($memNum != 0) {
             $q = $dbc->prepare_statement("SELECT FirstName,LastName\n                    FROM {$OP}custdata\n                    WHERE CardNo=? AND personNum=1");
             $r = $dbc->exec_statement($q, array($memNum));
             if ($dbc->num_rows($r) == 0) {
                 $this->errors .= "<em>Error: no such member: " . $memNum . "</em>" . "<br /><br />" . "<a href=\"\" onclick=\"back(); return false;\">Back</a>";
                 return True;
             }
             $row = $dbc->fetch_row($r);
             $this->name1 = $row['FirstName'] . ' ' . $row['LastName'];
         }
     }
     /* error check of inputs from form
      */
     if ($this->mode != 'init') {
         $this->dept = FormLib::get_form_value('dept');
         $this->amount = FormLib::get_form_value('amount');
         $this->cn1 = FormLib::get_form_value('memFrom');
         $this->cn2 = FormLib::get_form_value('memTo');
         $this->comment = FormLib::get_form_value('comment');
         /* If full URL is used to go back to the Transfer form
          * compose the search string so the parts op filled out aren't lost.
          * I don't know that this was ever used or worked.
          */
         foreach ($_REQUEST as $name => $value) {
             if (substr($name, 0, 6) != "submit") {
                 $item = "{$name}={$value}";
                 if (!in_array("{$item}", $this->hiddenSearch)) {
                     $this->hiddenSearch[] = "{$item}";
                 }
             }
         }
         $this->hiddenSearchString = "?" . implode('&amp;', $this->hiddenSearch);
         /* This "back" technique allows the form to display but loses any
          *  input values.
          * Not all of these errors are actually possible as the form now is.
          */
         $backLabel = _("Return to Transfer form");
         if (!isset($this->depts[$this->dept])) {
             $this->errors .= "<em>Error: Payment department doesn't exist</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ("{$this->amount}" == "") {
             $this->errors .= "<em>Error: please enter an amount to transfer</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->amount < 0) {
             $this->errors .= "<em>Error: amount to transfer given (" . $this->amount . ") is negative.</em>" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if (!is_numeric($this->amount)) {
             $this->errors .= "<em>Error: amount to transfer given (" . $this->amount . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if (!is_numeric($this->cn1)) {
             $this->errors .= "<em>Error: transfer 'From' member given (" . $this->cn1 . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn1 == 0) {
             $this->errors .= "<em>Error: choose a  member to transfer 'From'</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if (!is_numeric($this->cn2)) {
             $this->errors .= "<em>Error: transfer 'To' member given (" . $this->cn2 . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn1 == $this->cn2) {
             $this->errors .= "<em>Error: 'From' and 'To' cannot be the same</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn2 == 0) {
             $this->errors .= "<em>Error: choose a member to tranfser 'To'</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn1 > 0) {
             $q = "SELECT c.FirstName, c.LastName, b.availableBalance\n                    FROM {$OP}custdata c\n                    JOIN CCredMemCreditBalance b ON c.CardNo = b.cardNo\n                    WHERE c.CardNo=? AND c.personNum=1\n                    AND b.programID =" . $this->programID . "";
             $s = $dbc->prepare_statement($q);
             $r = $dbc->exec_statement($s, array($this->cn1));
             if ($dbc->num_rows($r) == 0) {
                 $this->errors .= "<em>Error: no such member: " . $this->cn1 . "</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
                 return True;
             }
             $row = $dbc->fetch_row($r);
             $this->name1 = $row['FirstName'] . ' ' . $row['LastName'];
         } else {
             $this->name1 = "Account Adjustment";
         }
         if ($this->mode == 'confirm' && $this->name1 != 'Account Adjustment' && $this->negativeBalanceOK == False && $row['availableBalance'] < $this->amount) {
             $this->errors .= "<em>Error: you may not transfer more: \$" . $this->amount . " than the Available Balance in the account: \$" . $row['availableBalance'] . "</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         $q = $dbc->prepare_statement("SELECT FirstName,LastName\n                FROM {$OP}custdata\n                WHERE CardNo=? AND personNum=1");
         $r = $dbc->exec_statement($q, array($this->cn2));
         if ($dbc->num_rows($r) == 0) {
             $this->errors .= "<em>Error: no such member: " . $this->cn2 . "</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         $row = $dbc->fetch_row($r);
         $this->name2 = $row['FirstName'] . ' ' . $row['LastName'];
     }
     return True;
     // preprocess()
 }
示例#3
0
    /** The form for specifying the report
     */
    function form_content()
    {
        global $FANNIE_PLUGIN_SETTINGS;
        $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
        ?>
<div id=main>    
<?php 
        if (isset($this->errors[0])) {
            echo "<p style='font-family:Arial; font-size:1.5em;'>";
            echo "<b>Errors in previous run:</b>";
            $sep = "<br />";
            foreach ($this->errors as $error) {
                echo "{$sep}{$error}";
            }
            echo "</p>";
        }
        ?>
</div><!-- /#main -->

<!-- Bootstrap-coded begins -->
<form method = "get" action="ProgramEventsReport.php" class="form-horizontal">
<div class="row">
    <div class="col-sm-6">
        <div class="form-group">
            <label class="col-sm-4 control-label">Program</label>
            <div class="col-sm-8">
<?php 
        echo "<select id='programID' name='programID' class='form-control'>";
        echo "<option value=''>Choose a Program</option>";
        $ccpModel = new CCredProgramsModel($dbc);
        $today = date('Y-m-d');
        foreach ($ccpModel->find() as $prog) {
            $desc = $prog->programName();
            if ($prog->active() == 0) {
                $desc .= " (inactive)";
            }
            if ($prog->startDate() > $today) {
                $desc .= " (Starts {$prog->startDate()})";
            }
            if ($prog->endDate() != 'NULL' && $prog->endDate() != '0000-00-00' && $prog->endDate() < $today) {
                $desc .= " (Ended {$prog->endDate()})";
            }
            printf("<option value='%d'%s>%s</option>", $prog->programID(), $this->pid == $prog->programID() ? " SELECTED" : "", $desc);
        }
        echo "</select>";
        ?>
            </div><!-- /.col-sm-8 -->
        </div><!-- /.form-group -->
    </div><!-- /.col-sm-6 end of left col -->
</div><!-- /.row -->

<div class="row">
    <div class="col-sm-6"><!-- start left col -->
        <div class="form-group">
            <label class="col-sm-4 control-label"> </label>
            <div class="col-sm-8">
                <p class="explain" style="float:none; margin:0 0 0 0.5em;">
<span style='font-weight:bold;'>Leave dates empty to report on the whole life of the program.</span>
<br/>The final Balance is relative to the Balance at Date Start .</p>
            </div>
        </div><!-- /.form-group -->
    </div><!-- /.col-sm-6 end of left col -->
</div><!-- /.row -->

<div class="row">
    <div class="col-sm-6"><!-- start left col -->
        <div class="form-group">
            <label class="col-sm-4 control-label">Start Date</label>
            <div class="col-sm-8">
                <input type=text id=date1 name=date1 class="form-control date-field" /><!-- required / -->
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">End Date</label>
            <div class="col-sm-8">
                <input type=text id=date2 name=date2 class="form-control date-field" /><!-- required / -->
            </div>
        </div>
        <div class="form-group">
            <label for="sortable" class="col-sm-4 control-label"
title="Tick to display with sorting from column heads; un-tick for a plain formt."
>Sort on Column Heads</label>
            <input type="checkbox" name="sortable" id="sortable" CHECKED />
        </div>
    </div><!-- /.col-sm-6 -->
    <div class="col-sm-5"><!-- start right col -->
        <div class="form-group">
<?php 
        echo FormLib::date_range_picker();
        ?>
                            
        </div>
    </div><!-- /.col-sm-5 -->
</div><!-- /.row -->
<p>
        <button type=submit name=submit value="Create Report" class="btn btn-default">Create Report</button>
        <!-- button type=reset name=reset class="btn btn-default">Start Over</button -->
</p>
            <input type=hidden name=card_no id=card_no value=0  />
</form><!-- /.form-horizontal -->

<!-- Bootstrap-coded ends -->
<?php 
        // /form_content()
    }
示例#4
0
 function preprocess()
 {
     global $FANNIE_CORRECTION_CASHIER, $FANNIE_CORRECTION_LANE, $FANNIE_CORRECTION_DEPT;
     global $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     if (isset($FANNIE_CORRECTION_CASHIER)) {
         $this->CORRECTION_CASHIER = $FANNIE_CORRECTION_CASHIER;
     }
     if (isset($FANNIE_CORRECTION_LANE)) {
         $this->CORRECTION_LANE = $FANNIE_CORRECTION_LANE;
     }
     if (isset($FANNIE_CORRECTION_DEPT)) {
         $this->CORRECTION_DEPT = $FANNIE_CORRECTION_DEPT;
     }
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors .= _("Error: The Coop Cred Plugin is not enabled.");
         return True;
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         $this->errors .= _("Error: Coop Cred Database not named in Plugin Settings.");
         return True;
     }
     if (FormLib::get_form_value('programID', False) !== False) {
         $this->programID = FormLib::get_form_value('programID');
     } else {
         $this->errors .= "<em>" . _("Error: ") . _("Program ID not supplied.") . "</em>" . "";
         return True;
     }
     if (FormLib::get_form_value('programID') == "0") {
         $backLabel = _("Return to Member Editor");
         $this->errors .= "<em>" . _("Warning: ") . _("The Member does not yet belong to a Program.") . "<br />" . _("Please add him/her to a Program, Save, and Edit again to do the Transfer.") . "</em>" . "<br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>" . "";
         return True;
     }
     $ccpModel = new CCredProgramsModel($dbc);
     $ccpModel->programID($this->programID);
     $inputOK = null;
     $prog = array_pop($ccpModel->find());
     if ($prog == null) {
         $this->errors .= "<em>Error: Program ID {$this->programID} is not known.</em>";
         return True;
     }
     $inputOK = $prog->inputOK();
     $this->programPaymentDepartment = $prog->paymentDepartment();
     $this->dept = $prog->paymentDepartment();
     $this->programName = $prog->programName();
     $this->inputTenderType = $prog->inputTenderType();
     $this->depts[$this->dept] = $this->programName;
     if (FormLib::get_form_value('memEDIT', False) !== False) {
         $this->memberBeingEdited = FormLib::get_form_value('memEDIT');
     }
     if (FormLib::get_form_value('submit1', False) !== False) {
         $this->mode = 'confirm';
     } elseif (FormLib::get_form_value('submit2', False) !== False) {
         $this->mode = 'finish';
     }
     if ($this->mode == 'init') {
         $memNum = FormLib::get_form_value('memIN');
         if ($memNum != 0) {
             $q = $dbc->prepare_statement("SELECT FirstName,LastName\n                    FROM {$FANNIE_OP_DB}{$dbc->sep()}custdata\n                    WHERE CardNo=? AND personNum=1");
             $r = $dbc->exec_statement($q, array($memNum));
             if ($dbc->num_rows($r) == 0) {
                 $this->errors .= "<em>Error: no such member: " . $memNum . "</em>" . "<br /><br />" . "<a href=\"\" onclick=\"back(); return false;\">Back</a>";
                 return True;
             }
             $row = $dbc->fetch_row($r);
             $this->name1 = $row['FirstName'] . ' ' . $row['LastName'];
         }
     }
     // error check inputs
     if ($this->mode != 'init') {
         $this->dept = FormLib::get_form_value('dept');
         $this->amount = FormLib::get_form_value('amount');
         $this->cn1 = FormLib::get_form_value('memFrom');
         $this->cn2 = FormLib::get_form_value('memTo');
         $this->comment = FormLib::get_form_value('comment');
         /* This "back" technique allows the form to display but loses any
          *  input values it had.
          */
         $backLabel = "Return to Input form";
         if (!isset($this->depts[$this->dept])) {
             $this->errors .= "<em>Error: Payment department doesn't exist</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ("{$this->amount}" == "") {
             $this->errors .= "<em>Error: please enter an amount to input</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->amount < 0) {
             $this->errors .= "<em>Error: amount to input given (" . $this->amount . ") is negative.</em>" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if (!is_numeric($this->amount)) {
             $this->errors .= "<em>Error: amount to input given (" . $this->amount . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if (!is_numeric($this->cn1)) {
             $this->errors .= "<em>Error: input 'From' member given (" . $this->cn1 . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         /* Since op. doesn't choose this in this Tool no need to check value.
            if ($this->cn1 == 0) {
                $this->errors .= "<em>Error: choose a  member to input 'From'</em>"
                    ."<br /><br />"
                    ."<a href=\"javascript:history.back();\">{$backLabel}</a>";
                return True;
            }
             */
         if (!is_numeric($this->cn2)) {
             $this->errors .= "<em>Error: input 'To' member given (" . $this->cn2 . ") isn't a number</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn2 == 0) {
             $this->errors .= "<em>Error: choose a member to input 'To'</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn1 == $this->cn2) {
             $this->errors .= "<em>Error: 'From' and 'To' cannot be the same</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         if ($this->cn1 > 0) {
             $q = $dbc->prepare_statement("SELECT FirstName,LastName\n                    FROM custdata\n                    WHERE CardNo=? AND personNum=1");
             $r = $dbc->exec_statement($q, array($this->cn1));
             if ($dbc->num_rows($r) == 0) {
                 $this->errors .= "<em>Error: no such member: " . $this->cn1 . "</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
                 return True;
             }
             $row = $dbc->fetch_row($r);
             $this->name1 = $row['FirstName'] . ' ' . $row['LastName'];
         } else {
             $this->name1 = "Account Adjustment";
         }
         $q = $dbc->prepare_statement("SELECT FirstName,LastName\n                FROM {$FANNIE_OP_DB}{$dbc->sep()}custdata\n                WHERE CardNo=? AND personNum=1");
         $r = $dbc->exec_statement($q, array($this->cn2));
         if ($dbc->num_rows($r) == 0) {
             $this->errors .= "<em>Error: no such member: " . $this->cn2 . "</em>" . "<br /><br />" . "<a href=\"javascript:history.back();\">{$backLabel}</a>";
             return True;
         }
         $row = $dbc->fetch_row($r);
         $this->name2 = $row['FirstName'] . ' ' . $row['LastName'];
     }
     return True;
 }
示例#5
0
 function SaveFormData($memNum)
 {
     global $FANNIE_ROOT;
     //$dbc = $this->db();
     global $FANNIE_URL;
     global $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         return '';
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         return '';
     }
     // Test probably not necessary.
     if (!class_exists("CCredMembershipsModel")) {
         $dbc->logger("Had to include CCredMembershipsModel");
         include $FANNIE_ROOT . 'modules/plugins2.0/CoopCred/models/CCredMembershipsModel.php';
     }
     // Test probably not necessary.
     if (!class_exists("CCredProgramsModel")) {
         $dbc->logger("Had to include CCredProgramsModel");
         include $FANNIE_ROOT . 'modules/plugins2.0/CoopCred/models/CCredProgramsModel.php';
     }
     // For Coop Cred limit always 0.
     $limit = (int) FormLib::get_form_value('CC_limit', 0);
     $credit_ok = FormLib::get_form_value('use_coop_cred', '') !== '' ? 1 : 0;
     $programID = (int) FormLib::get_form_value('ccred_program', 0);
     $maxCreditBalance = FormLib::get_form_value('maxbal', 0.0);
     if ($maxCreditBalance > 0) {
         $maxCreditBalance = $maxCreditBalance * -1;
     }
     /* For Program Bank members programID is never > 0.
      */
     if ($programID > 0) {
         $ccmModel = new CCredMembershipsModel($dbc);
         $ccmModel->cardNo($memNum);
         $ccmModel->programID($programID);
         /* There should be one or none.
          * find() returns an array, possibly empty, so foreach is needed.
          */
         $test = false;
         $saved = 0;
         foreach ($ccmModel->find() as $obj) {
             $saved++;
             $obj->creditOK($credit_ok);
             $obj->creditLimit($limit);
             $obj->maxCreditBalance($maxCreditBalance);
             $now = date('Y-m-d H:i:s');
             $obj->modified($now);
             /*$obj->modifiedBy($auth-user-id);
              * Like $name = FannieAuth::checkLogin
              * then modifiedBy = FannieAuth::getUID($name)
              * Not sure if keeping mod/modBy here is worth it since
              *  FannieDispatch::logUsage is called by FD::go,
              *  but not for this class alone.
              * I only want to log actual changes, which I can't detect yet.
              */
             $test = $obj->save();
             if ($test === false) {
                 break;
             }
             /* During testing pTLCC writes string error messages to Fannie log.
              * There doesn't seem to be a mechanism for displaying them
              *  if they are returned here.
              */
             $laneTest = $obj->pushToLanesCoopCred();
             if ($laneTest != true) {
                 break;
             }
         }
         /* I.e. was it an update? */
         if ($saved > 0) {
             if ($test === false) {
                 return 'Error: Problem updating Coop Cred membership data.<br />';
             }
         } else {
             // Only add if being enabled.
             if ($credit_ok) {
                 $ccmModel->creditOK($credit_ok);
                 $ccmModel->creditLimit($limit);
                 $ccmModel->maxCreditBalance($maxCreditBalance);
                 $now = date('Y-m-d H:i:s');
                 $ccmModel->modified($now);
                 //$ccmModel->modifiedBy($auth-user-id);
                 /* Get (default) membership values, esp. *OK,
                  *  for fields not entered, from the Program.
                  */
                 $ccpModel = new CCredProgramsModel($dbc);
                 $ccpModel->programID($programID);
                 foreach ($ccpModel->find() as $prog) {
                     $ccmModel->inputOK($prog->inputOK());
                     $ccmModel->transferOK($prog->transferOK());
                     break;
                 }
                 $test = $ccmModel->save();
                 if ($test === false) {
                     return 'Error: Problem adding Coop Cred membership data.<br />';
                 }
                 /* During testing pTLCC writes string error messages to Fannie log.
                  * There doesn't seem to be a mechanism for displaying them
                  *  if they are returned here.
                  */
                 $laneTest = $ccmModel->pushToLanesCoopCred();
                 if ($laneTest != true) {
                     return 'Error: Problem adding Coop Cred membership data to lane.<br />';
                 }
             }
         }
     }
     // OK
     return '';
 }
示例#6
0
 /**
       OK to use the tender or make the input?
       @return True if all clear to charge or input to the program
                     message if not
       @param $pKey - a tenderType or paymentDepartment
  Note: Transfer-to-another member part is not done.
      *
      * Knowing tenderType or paymentDepartment and memberID
      * Step 1:
      * - Find the program
      * Step 2:
      * - Is the program active?
      * Step 3:
      * - Is the member in it? CCredMemberships record exists.
      * - Is the membership in the program active?
      * x Is there enough to cover the amount?
 */
 public static function programOK($pKey = '', $conn = '')
 {
     global $CORE_LOCAL;
     if (!$CORE_LOCAL->get("memberID")) {
         return _("Please enter the Member ID");
     }
     if ($conn == '') {
         $conn = self::ccDataConnect();
         if (!is_object($conn)) {
             return _("Coop Cred database connection failed:") . " {$conn}";
         }
     }
     $pKeyType = preg_match('/^\\d+$/', $pKey) ? 'Department' : 'Tender';
     $ccpModel = new CCredProgramsModel($conn);
     if ($pKeyType == 'Department') {
         $ccpModel->paymentDepartment($pKey);
     } else {
         $ccpModel->tenderType($pKey);
     }
     $pCount = 0;
     foreach ($ccpModel->find() as $pgm) {
         $pCount++;
         //$limit = $cdModel->ChargeLimit();
         //$prog['inputOK'] = $pgm->inputOK();
     }
     if ($pCount == 0) {
         return _("Error:") . " {$pKeyType}" . " '{$pKey}' " . _("is not used in any Coop Cred Program.");
     }
     if ($pCount > 1) {
         return _("Error:") . " {$pKeyType}" . " '{$pKey}' " . _("is used in more than one Coop Cred Program.");
     }
     $today = date('Y-m-d');
     if ($today < $pgm->startDate()) {
         return $pgm->programName() . _(" hasn't started yet.");
     }
     if ($today < $pgm->endDate() != '' && $today > $pgm->endDate()) {
         return $pgm->programName() . _(" is no longer operating.");
     }
     if (!$pgm->active()) {
         return $pgm->programName() . _(" is not active.");
     }
     if (!$pgm->creditOK()) {
         return $pgm->programName() . _(" is not accepting purchases at this time.");
     }
     /* These are only valid globally for calculations involving the
      * current tenderType or paymentDepartment.
      */
     $CORE_LOCAL->set("CCredProgramID", $pgm->programID());
     $programCode = "CCred{$pgm->programID()}";
     $CORE_LOCAL->set("CCredProgramCode", $programCode);
     /* Reset these in CoopCred::plugin_transaction_reset()
      */
     $CORE_LOCAL->set("{$programCode}programID", $pgm->programID());
     $CORE_LOCAL->set("{$programCode}programName", $pgm->programName());
     $CORE_LOCAL->set("{$programCode}paymentDepartment", $pgm->paymentDepartment());
     $CORE_LOCAL->set("{$programCode}paymentName", $pgm->paymentName());
     $CORE_LOCAL->set("{$programCode}paymentKeyCap", $pgm->paymentKeyCap());
     $CORE_LOCAL->set("{$programCode}tenderType", $pgm->tenderType());
     $CORE_LOCAL->set("{$programCode}tenderName", $pgm->tenderName());
     $CORE_LOCAL->set("{$programCode}tenderKeyCap", $pgm->tenderKeyCap());
     /* Membership info.
      * (At the moment members's name is not used, so a model query could be used.)
      */
     $query = "SELECT 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 {$CORE_LOCAL->get('pDatabase')}.custdata c\n                ON m.cardNo = c.CardNo\n            WHERE m.cardNo = ? AND m.programID = ? AND c.personNum=1";
     $statement = $conn->prepare_statement($query);
     if ($statement === False) {
         return "Error: prepare_statement() failed for query: {$query}";
     }
     $args = array((int) $CORE_LOCAL->get("memberID"), (int) $pgm->programID());
     $result = $conn->exec_statement($statement, $args);
     if ($result === False) {
         return "Error: exec_statement() failed for query: {$query} args:" . implode('|', $args);
     }
     $num_rows = $conn->num_rows($result);
     if ($num_rows == 0) {
         return _("Member ") . $CORE_LOCAL->get("memberID") . _(" is not registered for ") . $CORE_LOCAL->get("{$programCode}programName") . ".";
     }
     $mem = $conn->fetch_array($result);
     /* Suspended or not activated for either purchasing or input.
      */
     if (!$mem['creditOK']) {
         return _("Member #") . $CORE_LOCAL->get("memberID") . _(" is registered for ") . '<b>' . $CORE_LOCAL->get("{$programCode}programName") . '</b>' . _(" but may not use it") . _(" at this time") . ".";
     }
     /* May not put money into the program.
      */
     if ($pKeyType == "Department" && !$mem['inputOK']) {
         return _("Member #") . $CORE_LOCAL->get("memberID") . _(" may not pay into ") . $CORE_LOCAL->get("{$programCode}programName") . ".";
     }
     /* May not transfer to another member.
      * I can't think how this could be done at cash without a special popup.
      * Transfer among one's own accounts: input to one, tender from another.
      *  Test would be at point of tender and need a scan of localtemptrans
      *  for CoopCredDepartments, $CoopCredDepartmentsUsed.
      *   "Payments" better, "Inputs" even better.
      *  AND trans_status in ('','0') - not cancel, void, refund - what would that be?
      */
     $isTransfer = 0;
     if (!$mem['transferOK'] && $isTransfer) {
         return _("Member #") . $CORE_LOCAL->get("memberID") . _(" may not transfer Coop Cred to another Member") . ".";
     }
     $CORE_LOCAL->set("{$programCode}availCreditBalance", $mem['availCreditBalance']);
     $CORE_LOCAL->set("{$programCode}creditBalance", $mem['creditBalance']);
     return True;
     // programOK()
 }