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(); }
private function ajax_save_program() { global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']); $OP = $FANNIE_OP_DB . $dbc->sep(); /* Place to accumulate not-immediately-fatal messages * that will be displayed in the ajax-return-string. */ $returnMessage = ""; /* These are from the query (parameters) string in the AJAX request * and are the same as the input form id= values. */ $progno = FormLib::get_form_value('progno', 0); $progname = FormLib::get_form_value('progname', ''); $isactive = FormLib::get_form_value('isactive', 0); $startdate = FormLib::get_form_value('startdate', ''); $enddate = FormLib::get_form_value('enddate', ''); if ($enddate == 'NULL' || $enddate == '0000-00-00') { $enddate = ''; } $tendertype = FormLib::get_form_value('tendertype', ''); $tendername = FormLib::get_form_value('tendername', ''); $tenderkeycap = FormLib::get_form_value('tenderkeycap', ''); $inputtender = FormLib::get_form_value('inputtender', ''); $paymentid = FormLib::get_form_value('paymentid', 0); $paymentname = FormLib::get_form_value('paymentname', ''); $paymentkeycap = FormLib::get_form_value('paymentkeycap', ''); $bankid = FormLib::get_form_value('bankid', 0); $creditok = FormLib::get_form_value('creditok', 0); $maxcredit = FormLib::get_form_value('maxcredit', 0); $inputok = FormLib::get_form_value('inputok', 0); $transferok = FormLib::get_form_value('transferok', 0); $origTender = FormLib::get_form_value('origtender', ''); $origDepartment = FormLib::get_form_value('origdepartment', 0); $isnew = FormLib::get_form_value('isnew', 9); /* * Check for problems, conflicts mostly: */ $sMessage = ""; /* Each check */ /* Tender */ $sErrors = array(); $sargs = array(); $sq = "SELECT tenderType, programName\n FROM CCredPrograms \n WHERE tenderType = ? "; $sargs[] = $tendertype; if (!$isnew) { $sq .= "AND programID != ?"; $sargs[] = $progno; } $ss = $dbc->prepare($sq); $sr = $dbc->execute($ss, $sargs); while ($srow = $dbc->fetch_row($sr)) { $sErrors[] = $srow['programName']; } if (count($sErrors) > 0) { $sMessage .= sprintf("\nThe Tender %s is already in use by:\n", $tendertype); $sMessage .= implode("\n", $sErrors); $sMessage .= "\nPlease choose a different one." . "\nIf the one you need doesn't exist yet,\n" . " set it up in the Tenders Editor\n" . " and then edit this Program again." . "\nAlso see the Tender '?' Help." . ""; } /* Payment Department */ $sErrors = array(); $sargs = array(); $sq = "SELECT paymentDepartment, paymentName, programName\n FROM CCredPrograms \n WHERE paymentDepartment = ? "; $sargs[] = $paymentid; if (!$isnew) { $sq .= "AND programID != ?"; $sargs[] = $progno; } $ss = $dbc->prepare($sq); $sr = $dbc->execute($ss, $sargs); while ($srow = $dbc->fetch_row($sr)) { $sErrors[] = $srow['programName']; } if (count($sErrors) > 0) { $sMessage .= sprintf("\nThe Department %s is already in use by:\n", $paymentid); $sMessage .= implode("\n", $sErrors); $sMessage .= "\nPlease choose a different one." . "\nIf the one you need doesn't exist yet,\n" . " set it up in the Departments Editor\n" . " and then edit this Program again." . "\nAlso see the Department '?' Help." . ""; } /* Banker Department */ $sErrors = array(); $sargs = array(); $sq = "SELECT bankID, programName\n FROM CCredPrograms \n WHERE bankID = ? "; $sargs[] = $bankid; if (!$isnew) { $sq .= "AND programID != ?"; $sargs[] = $progno; } $ss = $dbc->prepare($sq); $sr = $dbc->execute($ss, $sargs); while ($srow = $dbc->fetch_row($sr)) { $sErrors[] = $srow['programName']; } if (count($sErrors) > 0) { $sMessage .= sprintf("\nThe Banker %s is already in use by:\n", $bankid); $sMessage .= implode("\n", $sErrors); $sMessage .= "\nPlease choose a different one." . "\nIf the one you need doesn't exist yet,\n" . " set it up in the Members Editor\n" . " and then edit this Program again." . "\nAlso see the Banker '?' Help." . ""; } /* After all checks done. */ if ($sMessage) { $sMessage = preg_replace("/^\n+/", "", $sMessage); $sMessage .= "\n\nNo current changes have been Saved."; echo $sMessage; return; } /* Save changes to or Create the Program proper. */ $model = new CCredProgramsModel($dbc); $model->programID($progno); $model->programName($progname); /* Cannot be active if any dummy's in use. */ $resetIsactive = False; if ($isactive == 1 && ($paymentid == $this->dummyDepartment || $tendertype == "{$this->dummyTenderCode}" || $bankid == $this->dummyBanker)) { $resetIsactive = True; $isactive = 0; } $model->active($isactive); $model->startDate($startdate); $model->endDate($enddate); $model->tenderType($tendertype); $model->tenderName($tendername); $model->tenderKeyCap($tenderkeycap); $model->inputTenderType($inputtender); $model->paymentDepartment($paymentid); $model->paymentName($paymentname); $model->paymentKeyCap($paymentkeycap); $model->bankID($bankid); $model->creditOK($creditok); $model->maxCreditBalance($maxcredit); $model->inputOK($inputok); $model->transferOK($transferok); $model->modified(date('Y-m-d H:i:s')); $model->modifiedBy($this->authUserNumber); /* save() decides UPDATE vs INSERT based on whether programID already * exists. */ $saved = $model->save(); if ($isnew == 1) { if ($saved === False) { echo 'Error: could not create Program'; return; } /* Get the programID that was assigned by auto-increment. */ $newQ = "SELECT LAST_INSERT_ID()"; $rslt = $dbc->query("{$newQ}"); if ($rslt === False) { $msg = sprintf("Failed: %s", $dbc->error()); echo $msg; return; } $rows = $dbc->num_rows($rslt); if ($rows > 0) { $row = $dbc->fetch_row($rslt); $retVal = $row[0]; } else { $retVal = 0; } if ($retVal == 0) { $msg = "Failed to return new Program id."; echo $msg; return; } $progno = $retVal; $returnMessage .= sprintf("\nCreated Program %s (#%d)", $progname, $progno); /* If there are no dummies, re-create the views. */ if ($paymentid != $this->dummyDepartment && $tendertype != "{$this->dummyTenderCode}" && $bankid != $this->dummyBanker) { $rslt = $this->updateViews($dbc); if ($rslt !== True) { if (stripos($rslt, "fatal") !== False) { echo $returnMessage . "\n{$rslt}"; return; } else { $returnMessage .= "\n{$rslt}"; } } } } else { if ($saved === False) { echo 'Error: could not save the changes to the Program'; return; } else { $returnMessage .= sprintf("\nSaved Program %s (#%d)", $progname, $progno); } /* During testing pTLCC writes string error messages to Fannie log. * All problems are noted in return value. */ $laneTest = $model->pushToLanesCoopCred(); if ($laneTest === true) { $returnMessage .= "\nUpdated lanes."; } else { if (is_string($laneTest)) { $returnMessage .= sprintf("\nError saving Program %s (#%d) to lanes: %s", $progname, $progno, $laneTest); } else { $returnMessage .= sprintf("\nError saving Program %s (#%d) to lanes.", $progname, $progno); } } } /* Membership of Banker in Program * Create new membership or change Banker to this Program. * Check first that Banker has only one membership, * that something has not gone wrong. */ if ($bankid == $this->dummyBanker) { $returnMessage .= "\nThe Program may not be actually used until " . "a real Banker is assigned."; } else { $ccmModel = new CCredMembershipsModel($dbc); $ccmModel->cardNo($bankid); /* Default values for new programs. * Should these be configurable? Probably. */ $mCreditBalance = 0.0; $mCreditLimit = 0.0; $mMaxCreditBalance = 0.0; $mCreditOK = 1; $mInputOK = 1; $mTransferOK = 1; // $found = 0; $memships = array(); foreach ($ccmModel->find() as $obj) { $found++; $memships[] = $obj->programID(-1); /* Keep the values of an existing membership. * If it changes Programs. * Really a good idea? * If they, esp creditBalance, are not 0 catastrophe may ensue! */ $mCreditBalance = $obj->creditBalance(); $mCreditLimit = $obj->creditLimit(); $mMaxCreditBalance = $obj->maxCreditBalance(); $mCreditOK = $obj->creditOK(); $mInputOK = $obj->inputOK(); $mTransferOK = $obj->transferOK(); } if ($found > 1) { $msg = "Banker %d is already associated with more than one " . "(in fact %d) Program: %s" . "\nPlease use a different one."; echo $returnMessage . sprintf("\n{$msg}", $bankid, $found, implode(', ', $memships)); return; } $ccmModel = new CCredMembershipsModel($dbc); $ccmModel->cardNo($bankid); $ccmModel->programID($progno); $ccmModel->creditBalance($mCreditBalance); $ccmModel->creditLimit($mCreditLimit); $ccmModel->maxCreditBalance($mMaxCreditBalance); $ccmModel->creditOK($mCreditOK); $ccmModel->inputOK($mInputOK); $ccmModel->transferOK($mCreditOK); $ccmModel->isBank(1); $ccmModel->modified(date('Y-m-d H:i:s')); $ccmModel->modifiedBy($this->authUserNumber); $membershipSaved = $ccmModel->save(); if ($membershipSaved === False) { $msg = "Adding or updating membership in Program %d for Banker %d failed."; echo $returnMessage . sprintf("\n{$msg}", $progno, $bankid); return; } /* Membership of Banker in Program * Create new membership or change Banker to this Program. * Check first that Banker has only one membership, * that something has not gone wrong. */ $ccmModel = new CCredMembershipsModel($dbc); $ccmModel->cardNo($bankid); /* There should be one or none. * find() returns an array, possibly empty, so foreach is needed. */ /* Default values for new programs. * Should these be configurable? Probably. */ $mCreditBalance = 0.0; $mCreditLimit = 0.0; $mMaxCreditBalance = 0.0; $mCreditOK = 1; $mInputOK = 1; $mTransferOK = 1; // $found = 0; $memships = array(); foreach ($ccmModel->find() as $obj) { $found++; $memships[] = $obj->programID(-1); /* Keep the values of an existing membership. * If it changes Programs. * Really a good idea? If they are not 0 catastrophe may ensue! */ $mProgramID = $obj->programID(); $mCreditBalance = $obj->creditBalance(); $mCreditLimit = $obj->creditLimit(); $mMaxCreditBalance = $obj->maxCreditBalance(); $mCreditOK = $obj->creditOK(); $mInputOK = $obj->inputOK(); $mTransferOK = $obj->transferOK(); } if ($found > 1) { $msg = "Banker %d already has more than one (in fact %d) memberships: %s"; echo $returnMessage . sprintf("\n{$msg}", $bankid, $found, implode(', ', $memships)); return; } $ccmModel = new CCredMembershipsModel($dbc); $ccmModel->cardNo($bankid); $ccmModel->programID($progno); $ccmModel->creditBalance($mCreditBalance); $ccmModel->creditLimit($mCreditLimit); $ccmModel->maxCreditBalance($mMaxCreditBalance); $ccmModel->creditOK($mCreditOK); $ccmModel->inputOK($mInputOK); $ccmModel->transferOK($mCreditOK); $ccmModel->isBank(1); $ccmModel->modified(date('Y-m-d H:i:s')); $ccmModel->modifiedBy($this->authUserNumber); $membershipSaved = $ccmModel->save(); if ($membershipSaved === False) { $msg = "Adding or updating membership in Program %d for Banker %d failed."; $returnMessage .= sprintf("\n{$msg}", $progno, $bankid); } // not dummyBanker } /* #'u Updates to Fannie tables */ if ($tendertype == $this->dummyTenderCode) { $returnMessage .= "\nThe Program may not be actually used until " . "a real Tender is assigned."; } else { if ($tendername != "") { $opQ = "UPDATE {$OP}tenders\n SET TenderName = ?\n WHERE TenderCode = ?"; $opArgs = array(); $opArgs[] = $tendername; $opArgs[] = $tendertype; $opS = $dbc->prepare($opQ); $opR = $dbc->execute($opS, $opArgs); if ($opR === False) { $returnMessage .= "\nSaved changes to the Program proper but updating the " . "Tender name in CORE Backend failed."; } } } if ($paymentid == $this->dummyDepartment) { $returnMessage .= "\nThe Program may not be actually used until " . "a real Input/Payment is assigned."; } else { if ($paymentname != "") { $opQ = "UPDATE {$OP}departments\n SET dept_name = ?\n WHERE dept_no = ?"; $opArgs = array(); $opArgs[] = $paymentname; $opArgs[] = $paymentid; $opS = $dbc->prepare($opQ); $opR = $dbc->execute($opS, $opArgs); if ($opR === False) { $returnMessage .= "\nSaved changes to the Program proper but updating the " . "Department name in CORE Backend failed."; } } } /* Update views if Department or Tender have changed and * as long as neither is dummy. */ if ($paymentid != $origDepartment || $tendertype != $origTender) { if ($paymentid != $this->dummyDepartment && $tendertype != "{$this->dummyTenderCode}" && $bankid != $this->dummyBanker) { $rslt = $this->updateViews($dbc); if ($rslt !== True) { if (stripos($rslt, "fatal") !== False) { echo $returnMessage . "\n{$rslt}"; return; } else { $returnMessage .= "\n{$rslt}"; } } else { $returnMessage .= "\nUpdated views."; } } } if ($resetIsactive) { $returnMessage .= "\nThe Program has been marked Not-Active because " . "one or more dummy values are in use."; } $returnMessage = preg_replace("/^\n+/", "", $returnMessage); echo $returnMessage; // ajax_save_program() }
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('&', $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() }
/** 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() }
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; }
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 ''; }
/** 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() }