Example #1
0
 public function get_id_view()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $patronage = new PatronageModel($dbc);
     $patronage->cardno($this->id);
     $patronage->FY(FormLib::get('fy'));
     $exists = $patronage->load();
     if ($exists) {
         return '<div class="alert alert-danger">Member ' . $this->id . ' already has
             a patronage entry for ' . FormLib::get('fy') . '</div>';
     }
     $workingP = $dbc->prepare('
         SELECT net_purch 
         FROM patronage_workingcopy
         WHERE FY=?
             AND cardno=?');
     $workingR = $dbc->execute($workingP, array(FormLib::get('fy'), $this->id));
     if (!$workingR || $dbc->num_rows($workingR) == 0) {
         return '<div class="alert alert-danger">Member ' . $this->id . ' has
             no patronage info for ' . FormLib::get('fy') . '</div>';
     }
     $workingW = $dbc->fetch_row($workingR);
     $infoP = $dbc->prepare('
         SELECT SUM(net_purch) AS spendingTotal,
             SUM(tot_pat) AS patronageTotal,
             SUM(cash_pat) AS cashTotal,
             SUM(equit_pat) AS retainedTotal
         FROM patronage AS p
         WHERE FY=?');
     $infoR = $dbc->execute($infoP, array(FormLib::get('fy')));
     $infoW = $dbc->fetch_row($infoR);
     $ratio = $workingW['net_purch'] / $infoW['spendingTotal'];
     $cash = round($infoW['cashTotal'] * $ratio, 2);
     $equity = round($infoW['retainedTotal'] * $ratio, 2);
     $ret = '<form method="post"> 
         <input type="hidden" name="id" value="' . $this->id . '" />
         <input type="hidden" name="fy" value="' . FormLib::get('fy') . '" />
         <div class="form-group">
             <label>Suggested Cash Portion</label>
             <div class="input-group">
                 <span class="input-group-addon">$</span>
                 <input type="text" required class="form-control" name="cash" value="' . $cash . '" />
             </div>
         </div>
         <div class="form-group">
             <label>Suggested Retained Portion</label>
             <div class="input-group">
                 <span class="input-group-addon">$</span>
                 <input type="text" required class="form-control" name="retain" value="' . $equity . '" />
             </div>
         </div>
         <div class="form-group">
             <button class="btn btn-default" type="submit">Submit
         </div>
         </form>';
     return $ret;
 }
 function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $cn_index = $this->get_column_index('check_no');
     $td_index = $this->get_column_index('tdate');
     $p = new PatronageModel($dbc);
     foreach ($linedata as $line) {
         $check_no = $line[$cn_index];
         if (!is_numeric($check_no)) {
             continue;
         }
         // skip bad record
         $p->check_number($check_no);
         $matches = $p->find();
         if (count($matches) == 0) {
             $this->stats['errors'][] = 'No check on file with #' . $check_no;
             continue;
         }
         // there shouldn't be more than one match
         // but loop anyway
         foreach ($matches as $obj) {
             if ($obj->cashed_date() != '') {
                 // if check has already been marked as cash, do not
                 // update the date. just leave it as is and
                 // count the record as imported successfully
                 $this->stats['imported']++;
             } else {
                 // tag the record with today's date OR the
                 // spreadsheet-supplied date
                 $tdate = date('Y-m-d');
                 if ($td_index !== false && $line[$td_index] != '') {
                     $stamp = strtotime($line[$td_index]);
                     if ($stamp) {
                         $tdate = date('Y-m-d', $stamp);
                     }
                 }
                 $obj->cashed_date($tdate);
                 $updated = $obj->save();
                 if ($updated) {
                     $this->stats['imported']++;
                 } else {
                     $this->stats['errors'][] = $dbc->error();
                 }
             }
         }
     }
     return true;
 }
Example #3
0
 public function testPatronageChecks()
 {
     $config = FannieConfig::factory();
     $task = new PatronageCheckTask();
     $dbc = FannieDB::get($config->get('OP_DB'));
     $dbc->query('TRUNCATE TABLE patronage');
     $p = new PatronageModel($dbc);
     $p->cardno(1);
     $p->FY(2000);
     $p->check_number(1);
     $p->cashed_date(null);
     $p->cashed_here(0);
     $p->save();
     $dbc = FannieDB::get($config->get('TRANS_DB'));
     $dbc->query('TRUNCATE TABLE dlog_15');
     $d = new DLog15Model($dbc);
     $d->tdate('2000-01-01 00:00:00');
     $d->trans_type('T');
     $d->description('REBATE CHECK');
     $d->total(1.23);
     $d->card_no(1);
     $d->save();
     $task->run();
     $dbc = FannieDB::get($config->get('OP_DB'));
     $p->reset();
     $p->cardno(1);
     $p->FY(2000);
     $loaded = $p->load();
     $this->assertEquals(true, $loaded, 'Failed to load patronage record');
     $this->assertEquals('2000-01-01 00:00:00', $p->cashed_date(), 'Cashed date missing');
     $this->assertEquals(1, $p->cashed_here(), 'Not marked as cashed');
 }
Example #4
-1
 public function post_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $fy = FormLib::get('fy');
     $per_page = FormLib::get('per_page');
     $custdata = new CustdataModel($dbc);
     $meminfo = new MeminfoModel($dbc);
     $query = $dbc->prepare('
         SELECT p.cardno,
             p.cash_pat,
             m.zip,
             p.check_number
         FROM patronage AS p
             INNER JOIN meminfo AS m ON p.cardno=m.card_no
             INNER JOIN custdata AS c ON p.cardno=c.CardNo AND c.personNum=1
         WHERE p.FY=?
         ORDER BY m.zip,
             c.LastName,
             c.FirstName');
     $result = $dbc->execute($query, array($fy));
     $pdf = new FPDF('P', 'mm', 'Letter');
     $pdf->SetMargins(6.35, 6.35, 6.35);
     // quarter-inch margins
     $pdf->SetAutoPageBreak(false);
     $filename = '';
     $this->files = array();
     $filenumber = 1;
     set_time_limit(0);
     while ($w = $dbc->fetch_row($result)) {
         if (empty($filename)) {
             $filename = $filenumber . '-' . substr($w['zip'], 0, 5);
         }
         $dbc = FannieDB::get($FANNIE_OP_DB);
         $custdata->CardNo($w['cardno']);
         $custdata->personNum(1);
         $custdata->load();
         $meminfo->card_no($w['cardno']);
         $meminfo->load();
         if ($w['check_number'] == '') {
             $patronage = new PatronageModel($dbc);
             $patronage->cardno($w['cardno']);
             $patronage->FY($fy);
             $number = GumLib::allocateCheck($patronage, false);
             $dbc = FannieDB::get($FANNIE_OP_DB);
             $patronage->check_number($number);
             $patronage->save();
             $w['check_number'] = $number;
         }
         $pdf->AddPage();
         $pdf->Image('rebate_body.png', 10, 0, 190);
         $check = new GumCheckTemplate($custdata, $meminfo, $w['cash_pat'], 'Rebate ' . $fy, $w['check_number']);
         $check->renderAsPDF($pdf);
         if ($pdf->PageNo() == $per_page) {
             $filename .= '-' . substr($w['zip'], 0, 5) . '.pdf';
             $filenumber++;
             $pdf->Output('/tmp/' . $filename, 'F');
             $this->files[] = $filename;
             $filename = '';
             $pdf = new FPDF('P', 'mm', 'Letter');
             $pdf->SetMargins(6.35, 6.35, 6.35);
             // quarter-inch margins
             $pdf->SetAutoPageBreak(false);
         }
     }
     $filename .= '-End.pdf';
     $pdf->Output('/tmp/' . $filename, 'F');
     $this->files[] = $filename;
     return true;
 }