コード例 #1
0
ファイル: NotInUseTask.php プロジェクト: phpsmith/IS4C
 public function run()
 {
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $yesterday = date('Y-m-d', strtotime('yesterday'));
     $url = $this->config->get('URL');
     $host = php_uname('n');
     $dtrans = DTransactionsModel::selectDTrans($yesterday);
     $findP = $dbc->prepare('
         SELECT d.upc,
             d.description,
             d.department,
             p.inUse,
             count(*) AS occurences
         FROM ' . $dtrans . ' AS d ' . DTrans::joinProducts('d') . '
         WHERE d.trans_type=\'L\'
             AND d.trans_subtype=\'OG\'
             AND d.charflag=\'IU\'
             AND d.emp_no <> 9999
             AND d.register_no <> 99
             AND d.datetime BETWEEN ? AND ?
         GROUP BY d.upc,
             d.description,
             d.department,
             p.inUse
         HAVING SUM(d.quantity) <> 0
     ');
     $findR = $dbc->execute($findP, array($yesterday . ' 00:00:00', $yesterday . ' 23:59:59'));
     while ($w = $dbc->fetchRow($findR)) {
         $msg = sprintf('%s (%s) was sold %d times while not inUse', $w['description'], $w['upc'], $w['occurences']);
         $email = \COREPOS\Fannie\API\lib\AuditLib::getAddresses($w['department']);
         if ($email) {
             $subject = 'Not In Use Report';
             $from = "From: automail\r\n";
             $msg .= "\n";
             $msg .= "http://{$host}/{$url}item/ItemEditorPage.php?searchupc={$w['upc']}\n";
             mail($email, $subject, $msg, $from);
         } else {
             $this->cronMsg($msg);
         }
     }
 }