Example #1
0
 /**
   Suspends the current transaction
   If the remote server is available, it will be suspended
   there. Otherwise it is suspended locally.
   @return [string] transaction identifier
 */
 public static function suspendorder()
 {
     $query_a = "select emp_no, trans_no from localtemptrans";
     $db_a = Database::tDataConnect();
     $result_a = $db_a->query($query_a);
     $row_a = $db_a->fetch_array($result_a);
     $cashier_no = substr("000" . $row_a["emp_no"], -2);
     $trans_no = substr("0000" . $row_a["trans_no"], -4);
     $trans_num = ReceiptLib::receiptNumber();
     if (CoreLocal::get("standalone") == 0) {
         $db_a->add_connection(CoreLocal::get("mServer"), CoreLocal::get("mDBMS"), CoreLocal::get("mDatabase"), CoreLocal::get("mUser"), CoreLocal::get("mPass"), false, true);
         $cols = Database::getMatchingColumns($db_a, "localtemptrans", "suspended");
         $db_a->transfer(CoreLocal::get("tDatabase"), "select {$cols} from localtemptrans", CoreLocal::get("mDatabase"), "insert into suspended ({$cols})");
         $db_a->close(CoreLocal::get("mDatabase"), True);
     } else {
         $query = "insert into suspended select * from localtemptrans";
         $result = $db_a->query($query);
     }
     /* ensure the cancel happens */
     $cancelR = $db_a->query("UPDATE localtemptrans SET trans_status='X',charflag='S'");
     TransRecord::finalizeTransaction(true);
     CoreLocal::set("plainmsg", _("transaction suspended"));
     $recall_line = CoreLocal::get("standalone") . " " . CoreLocal::get("laneno") . " " . $cashier_no . " " . $trans_no;
     /**
       If the transaction is marked as complete but somehow did not
       actually finish, this will prevent the suspended receipt from
       adding tax/discount lines to the transaction
     */
     CoreLocal::set('End', 0);
     return $trans_num;
 }
Example #2
0
 private function doResume($reg, $emp, $trans)
 {
     $query_del = "DELETE FROM suspended WHERE register_no = " . $reg . " AND emp_no = " . $emp . " AND trans_no = " . $trans;
     $db_a = Database::tDataConnect();
     $success = false;
     // use SQLManager's transfer method when not in stand alone mode
     // to eliminate the cross server query - andy 8/31/07
     if (CoreLocal::get("standalone") == 0) {
         $db_a->add_connection(CoreLocal::get("mServer"), CoreLocal::get("mDBMS"), CoreLocal::get("mDatabase"), CoreLocal::get("mUser"), CoreLocal::get("mPass"));
         $cols = Database::getMatchingColumns($db_a, "localtemptrans", "suspended");
         // localtemptrans might not actually be empty; let trans_id
         // populate via autoincrement rather than copying it from
         // the suspended table
         if (substr($cols, -9) == ',trans_id') {
             $cols = substr($cols, 0, strlen($cols) - 9);
         }
         $remoteQ = "SELECT {$cols} \n                        FROM suspended \n                        WHERE \n                            register_no = {$reg} \n                            AND emp_no = {$emp}\n                            AND trans_no = {$trans}\n                            AND datetime >= " . date("'Y-m-d 00:00:00'") . "\n                        ORDER BY trans_id";
         $success = $db_a->transfer(CoreLocal::get("mDatabase"), $remoteQ, CoreLocal::get("tDatabase"), "insert into localtemptrans ({$cols})");
         if ($success) {
             $db_a->query($query_del, CoreLocal::get("mDatabase"));
         }
         $db_a->close(CoreLocal::get("mDatabase"), true);
     } else {
         // localtemptrans might not actually be empty; let trans_id
         // populate via autoincrement rather than copying it from
         // the suspended table
         $def = $db_a->table_definition('localtemptrans');
         $cols = '';
         foreach ($def as $name => $info) {
             if ($name == 'trans_id') {
                 continue;
             }
             $cols .= $name . ',';
         }
         $cols = substr($cols, 0, strlen($cols) - 1);
         $localQ = "SELECT {$cols} \n                        FROM suspended \n                        WHERE \n                            register_no = {$reg} \n                            AND emp_no = {$emp}\n                            AND trans_no = {$trans}\n                            AND datetime >= " . date("'Y-m-d 00:00:00'") . "\n                        ORDER BY trans_id";
         $success = $db_a->query("insert into localtemptrans ({$cols}) " . $localQ);
         if ($success) {
             $db_a->query($query_del);
         }
     }
     $query_update = "update localtemptrans set register_no = " . CoreLocal::get("laneno") . ", emp_no = " . CoreLocal::get("CashierNo") . ", trans_no = " . CoreLocal::get("transno");
     $db_a->query($query_update);
     /**
       Add a log record after succesfully
       resuming a suspended transaction.
       Log record added after resume so records
       preceeding the log record were part of
       the original transaction and records
       following the log record were part of
       the resumed transaction
     */
     if ($success) {
         TransRecord::addLogRecord(array('upc' => 'RESUME', 'description' => $emp . '-' . $reg . '-' . $trans, 'charflag' => 'SR'));
     }
     Database::getsubtotals();
 }