payment_methods = array("MC", "V", "A", "Disc", "Debit", "Check", "Cash", "Store Credit", "Gift Certificate"); } function cc_type_to_text($cc_type) { // cc type from enum field in orders_transactions_cc switch($cc_type) { case 'M': return('MasterCard'); case 'V': return('Visa'); case 'A': return('American Express'); case 'D': return('Discover'); default: return(FALSE); } } function open_win_receipt($order_id='',$batch='') { $qs = ($batch == '') ? 'id='.$order_id : 'batch='.$batch; return('window.open(\'/admin/orders/pos/receipt.hello?'.$qs.'\',\'receipt\',\'width=600,height=576,resizable=yes,scrollbars=no,directories=yes,location=yes,menubar=yes\')'); } function openwin_pos_add_item($w,$h,$qs,$qs_end='') { // returns the window.open code return('window.open(\'item_add.hello?'.$qs.'\''.$qs_end.',\'pos_item\',\'width='.$w.',height='.$h.',scrollbars=yes,resizable=yes,left=500,top=70,location=yes\');void 0;'); } function enter_transaction($Order, $amount, $payment_method, $order_id, $trans_dt='', $gc_sc='', $contact_id='', $notes='') { if(trim($amount) != '' && $amount != 0) { if($amount < 0) { $type = 'refund'; $amount = -$amount; // refund should be positive } else { $type = 'payment'; } } else { return(FALSE); } switch($payment_method) { case 'MC': $method = 'credit card'; $cc_type = 'M'; break; case 'V': $method = 'credit card'; $cc_type = 'V'; break; case 'A': $method = 'credit card'; $cc_type = 'A'; break; case 'Disc': $method = 'credit card'; $cc_type = 'D'; break; case 'Debit': $method = 'debit card'; break; case 'Check': $method = 'check'; break; case 'Cash': $method = 'cash'; break; case 'Store Credit': $method = 'store credit'; $notes = $gc_sc; break; case 'Gift Certificate': $method = 'gift certificate'; $notes = $gc_sc; break; default: return(FALSE); } if($tr_id = $Order->insert_transaction($amount, $type, $method, $notes)) { if($method == 'credit card') { $cc_gateway = 'moneytree'; // store $gateway_action = ($type == 'refund') ? 'CREDIT' : 'AUTH_CAPTURE'; // for store orders $reference_trans_id = ''; // used for refunds, captures, voids $Order->insert_cc_transaction($tr_id, '', '', '', '', '', '', $cc_gateway, $gateway_action, '', '', '', $cc_type); } elseif($method == 'store credit') { // if this is a payment and the gc_sc # is entered try to locate the sc id from store_credits and use it to insert a record into orders_transactions_sc // otherwise we don't have a record - could be an old one - send me an email to verify // if this is a newly issued sc for a return insert into store_credits and that id is used as the store credit # on the receipt (no receipt # should appear on recpt) if($type == 'payment') { // they are paying with a store credit if($gc_sc == '' || !$sc_id = Database::ado_get_one("SELECT id FROM ".Config::$db_tables['store_credits']." WHERE id='".addslashes($gc_sc)."'", "POS::enter_transaction")) { // either no # entered or not found $sc_id = 0; Utilities::notify(Config::$tech_email, "Bad SC #", "orders_transactions_id: $tr_id"); } } elseif($type == 'refund') { // we are issuing a store credit $scins = "INSERT INTO ".Config::$db_tables['store_credits']." VALUES(NULL, '$order_id', '$contact_id', NOW(), '')"; $sc_id = Database::ado_execute_query($scins, "POS::enter_transaction"); } Database::ado_execute_query("INSERT INTO ".Config::$db_tables['orders_transactions_sc']." VALUES(NULL, '$tr_id', '$sc_id')", "POS::enter_transaction"); } elseif($method == 'gift certificate') { // if the gc_sc # is entered for this payment then try to locate the gc id from gift_certificates and use it to insert a record into orders_transactions_gc // otherwise we don't have a record - could be an old one - send me an email to verify // if this is a newly issued sc for a return insert into store_credits and that id is used as the store credit # on the receipt (no receipt # should appear on recpt) if($type == 'payment') { // they are paying with a store credit if($gc_sc == '' || !$gc_id = Database::ado_get_one("SELECT id FROM ".Config::$db_tables['gift_certificates']." WHERE gc_number='".addslashes($gc_sc)."'", "POS::enter_transaction")) { // either no # entered or not found $gc_id = 0; Utilities::notify(Config::$tech_email, "Bad GC #", "orders_transactions_id: $tr_id"); } } elseif($type == 'refund') { $gc_number = ($gc_sc != '') ? $gc_sc : 0; $gcins = "INSERT INTO ".Config::$db_tables['gift_certificates']." VALUES(NULL, '$order_id', '$gc_number', '$amount', NOW(), '')"; $gc_id = Database::ado_execute_query($gcins, "POS::enter_transaction"); } $gctrins = "INSERT INTO ".Config::$db_tables['orders_transactions_gc']." VALUES(NULL, '$tr_id', '$gc_id')"; //echo $gctrins; Database::ado_execute_query($gctrins, "POS::enter_transaction"); } } return(TRUE); } function method_select($select_name, $first_option_text, $preselected) { $method_select = ''; return($method_select); } function store_credit_balance($sc_number) { //echo $sc_number; $balance = 0; //$DB->GetOne("SELECT amount FROM store_credits WHERE id='$sc_number'"); - old, before removing amount column //echo 'bal: '.$balance; $RS = Database::ado_execute_query("SELECT b.amount, b.trans_type FROM orders_transactions_sc a, orders_transactions b WHERE a.transactions_id=b.id AND a.store_credits_id='$sc_number'", "POS::store_credit_balance"); while($row = $RS->FetchRow()) { // can there be a refund here?? $amt = ($row['trans_type'] == 'refund') ? -$row['amount'] : $row['amount']; $balance -= $amt; $balance = round($balance,2); //echo '
bal: '.$balance; } return($balance); } } ?>