this is items + tax + ship - payments - return items - return tax + refunds. if items amount is 0 then shipping is not counted. public $payments_amount; // note this includes sc + gc public $refunds_amount; // note this includes sc + gc public $pending_payments_amount; public $pending_refunds_amount; public $transactions; function __Construct($order_id) { $this->id = $order_id; // initialize amounts $this->items_amount = 0; $this->items_amount_shipped = 0; $this->items_amount_returned = 0; $this->tax_amount = 0; $this->ship_amount = 0; $this->original_total_amount = 0; $this->total_amount = 0; $this->balance = 0; $this->payments_amount = 0; $this->refunds_amount = 0; $this->pending_payments_amount = 0; $this->pending_refunds_amount = 0; } function get_data() { $this->data = Database::ado_get_row("SELECT * FROM orders WHERE id='".$this->id."'", "Order::get_data"); } function get_amounts() { if(!isset($this->data)) { $this->get_data(); } if(!isset($this->items)) { $this->get_items(); // sets items_amount, tax_amount } $this->ship_amount = $this->data['ship_amount']; $this->original_total_amount = $this->original_items_amount + $this->original_tax_amount + $this->ship_amount; $this->total_amount = $this->items_amount + $this->tax_amount; if($this->data['order_status'] != 'canceled') { $this->total_amount += $this->ship_amount; } if(!isset($this->transactions)) { $this->get_transactions(); // sets $this->payments_amount, $this->refunds_amount } $this->set_balance(); } function set_balance() { //items + tax + ship - payments - return items - return tax + refunds //order amount (items amount incl tax + shipping) - payment amounts - return amounts + refunds. $this->balance = $this->items_amount + $this->tax_amount; if($this->data['order_status'] != 'canceled') { $this->balance += $this->ship_amount; } $this->balance -= $this->payments_amount; $this->balance += $this->refunds_amount; } function get_items() { // amounts issue: web and store work differently for returns - store custs return things that we can't find orig recpts for so almost all (some exceptions early on) returns are put on a new order. this sets order_items.item_action to 'return' and order_item_status.order_item_status to 'ret'. however, for the web we just set the status of orig item record to 'ret' and the item_action remains as 'purchase'. this must be accounted for. the rule is that the status field takes precedence. $this->items = array(); // order_items record data plus an array of order_item_status data (1 status value for each qty) $RS = Database::ado_execute_query("SELECT a.*, b.style_number FROM ".Config::$db_tables['order_items']." a, ".Config::$db_tables['inventory_items']." b WHERE a.item_id=b.id AND order_id=$this->id ORDER BY id", "Order::get_items"); while($row = $RS->FetchRow()) { $this->items[$row['id']] = $row; // get status(es) $this->items[$row['id']]['status'] = array(); $sel = "SELECT * FROM ".Config::$db_tables['order_item_status']." WHERE order_item_id = '".$row['id']."' ORDER BY id"; //echo $sel; $StatusRS = Database::ado_execute_query($sel, "Order::get_items"); // important to have a status record for each item (ie 2 records for qty 2) // consider making this a cron job - part of a db inconsistencies job if($StatusRS->RecordCount() != $row['item_qty']) { Utilities::notify(Config::$tech_email, 'Incorrect # of Order Item Status Records', "Order # ".$this->id." \nOrder Item #: ".$row['id']); } while($status_row = $StatusRS->FetchRow()) { $this->items[$row['id']]['status'][] = $status_row; if($status_row['order_item_status'] != 'cxc' && $status_row['order_item_status'] != 'cxs') { if($status_row['order_item_status'] == 'ret') { if($row['item_action'] == 'return') // mainly store returns but some web ones - see order 1867 { $this->original_items_amount -= $row['item_price']; $this->items_amount -= $row['item_price']; $this->original_tax_amount -= $row['item_tax']; $this->tax_amount -= $row['item_tax']; } else { // this was originally a purchased item $this->original_items_amount += $row['item_price']; $this->original_tax_amount += $row['item_tax']; } $this->items_amount_returned += $row['item_price']; } else { $this->original_items_amount += $row['item_price']; $this->items_amount += $row['item_price']; $this->original_tax_amount += $row['item_tax']; $this->tax_amount += $row['item_tax']; if($status_row['order_item_status'] == 'shp' || $status_row['order_item_status'] == 'snc') { $this->items_amount_shipped += $row['item_price']; } } } else { // a cancelled item $this->original_items_amount += $row['item_price']; $this->original_tax_amount += $row['item_tax']; } } } } function get_ois_data($ois_id) { return(Database::ado_get_row("SELECT * FROM ".Config::$db_tables['order_item_status']." WHERE id='$ois_id'", "OrderAdmin::get_ois_data")); } function get_ois_RS($oi_id) { // items will have multiple ois records if qty > 1 return(Database::ado_execute_query("SELECT * FROM ".Config::$db_tables['order_item_status']." WHERE order_item_id='$oi_id'", "OrderAdmin::get_ois_RS")); } function items_html($type='cust', $Forms='') { if(!isset($this->items)) { $this->get_items(); } $html = ' '; $today = date("Y-m-d"); if($type == 'admin') { // just do the status column - ship date, notes for later use $delivery_title = ($this->data['order_type'] == 'web') ? 'Ship Date [ie '.$today.']' : 'Pick Up Date'; $html .= ' '; } $html .= ' '; foreach($this->items as $item) { $item_cell = ''; if($type == 'admin' && $item['item_name'] != 'dummy item') { $item_cell .= ''; } $item_cell .= $item['item_designer_name']. ' '; $item_cell .= ($item['item_name'] != 'dummy item') ? $item['item_name'] : $item['item_description']; if($type == 'admin' && $item['style_number'] != '') { $item_cell .= ' ('.$item['style_number'].')'; } if($item['item_color'] != '') { $item_cell .= ' ('.$item['item_color'].')'; } if($item['item_size'] != '') { $item_cell .= ' ('.$item['item_size'].')'; } if($type == 'admin' && $item['item_name'] != 'dummy item') { $item_cell .= ''; } if($type == 'admin') { // status form // order item status options (get here once instead of getting for each order item) $order_item_status_options = Utilities::enum_get_options($field="order_item_status",$table="order_item_status"); //print_r($order_item_status_options); $num_noncancelled_items = 0; // use for qty, amount $status_form_table = '
ItemP.S. Status '.$delivery_title.' Price Quantity Amount
'; // there should be a record in order_item_status for each qty item (ie if qty = 3 there will be 3 records) $stRS = $this->get_ois_RS($item['id']); $stcount = 0; while($strow = $stRS->FetchRow()) { //echo $strow['id'].'
'; ++$stcount; $order_item_status = $strow['order_item_status']; if($order_item_status != 'cxc' && $order_item_status != 'cxs') { ++$num_noncancelled_items; } if($stcount > 1){$this->conf_html .= '
';} // packing slip checkbox for each item //$checkedOnOff = ($_) ? ' checked="checked"' : ''; $ps_checkbox_disabled_statuses = array('tbp', 'bck', 'tbs', 'cxc', 'cxs', 'ret', 'sto', 'lay', 'hol'); // these statuses don't allow putting the item in the packing slip $ps_checkbox_disabled = (in_array($order_item_status, $ps_checkbox_disabled_statuses)) ? ' disabled="disabled"' : ''; $ps_checkbox = ''; $pulldown_status_options = array(); if($order_item_status == 'sto') { $pulldown_status_options['sto'] = 'sto'; // can't change a sto status } elseif($order_item_status == 'lay') { $pulldown_status_options['lay'] = 'lay'; $pulldown_status_options['sto'] = 'sto'; // can only change lay to sto } elseif($order_item_status == 'tbp') { $pulldown_status_options['tbp'] = 'tbp'; $pulldown_status_options['bck'] = 'bck'; $pulldown_status_options['drp'] = 'drp'; $pulldown_status_options['tbs'] = 'tbs'; $pulldown_status_options['snc'] = 'snc'; $pulldown_status_options['shp'] = 'shp'; $pulldown_status_options['cxc'] = 'cxc'; $pulldown_status_options['cxs'] = 'cxs'; } elseif($order_item_status == 'tbs') { $pulldown_status_options['tbs'] = 'tbs'; $pulldown_status_options['snc'] = 'snc'; $pulldown_status_options['shp'] = 'shp'; $pulldown_status_options['cxc'] = 'cxc'; $pulldown_status_options['cxs'] = 'cxs'; } elseif($order_item_status == 'bck') { $pulldown_status_options['bck'] = 'bck'; $pulldown_status_options['tbs'] = 'tbs'; $pulldown_status_options['snc'] = 'snc'; $pulldown_status_options['shp'] = 'shp'; $pulldown_status_options['cxc'] = 'cxc'; $pulldown_status_options['cxs'] = 'cxs'; } elseif($order_item_status == 'drp') { $pulldown_status_options['drp'] = 'drp'; $pulldown_status_options['snc'] = 'snc'; $pulldown_status_options['shp'] = 'shp'; } elseif($order_item_status == 'snc') { $pulldown_status_options['snc'] = 'snc'; $pulldown_status_options['shp'] = 'shp'; // can only change snc status to shp for web orders } elseif($order_item_status == 'shp') { $pulldown_status_options['shp'] = 'shp'; $pulldown_status_options['ret'] = 'ret'; // can only change shp status to ret for web orders } elseif($order_item_status == 'cxc') { $pulldown_status_options['cxc'] = 'cxc'; $pulldown_status_options['bck'] = 'bck'; $pulldown_status_options['tbs'] = 'tbs'; $pulldown_status_options['snc'] = 'snc'; $pulldown_status_options['shp'] = 'shp'; $pulldown_status_options['cxs'] = 'cxs'; } elseif($order_item_status == 'cxs') { $pulldown_status_options['cxs'] = 'cxs'; $pulldown_status_options['bck'] = 'bck'; $pulldown_status_options['tbs'] = 'tbs'; $pulldown_status_options['snc'] = 'snc'; $pulldown_status_options['shp'] = 'shp'; $pulldown_status_options['cxc'] = 'cxc'; } elseif($order_item_status == 'ret') { $pulldown_status_options['ret'] = 'ret'; // can't change a status from ret } else { foreach($order_item_status_options as $op) { if($this->data['order_type'] == 'web' && ($op == 'sto' || $op == 'lay') ) { // only web statuses } else { $pulldown_status_options[$op] = $op; } } } $status_form_table .= ' '; } $status_form_table .= '
'; $order_item_delivery_date_val = ($strow['order_item_delivery_date'] != '0000-00-00') ? $strow['order_item_delivery_date'] : ''; $order_item_delivery_date_disabled = ($order_item_status == 'sto' || $order_item_status == 'cxc' || $order_item_status == 'cxs' || $order_item_status == 'ret') ? ' disabled="disabled"' : ''; $updt_submit_disabled = ($order_item_status == 'ret') ? ' disabled="disabled"' : ''; $status_form_table .= '
'.$ps_checkbox.' '.$Forms->generate_select_formfield("order_item_status[".$strow["id"]."]", $pulldown_status_options, '', $order_item_status).'  
'; } //$qty_adj = (isset($num_noncancelled_items)) ? $num_noncancelled_items : $item['item_qty']; //$item_amount = $qty_adj * $item['item_price']; $price_cell = ''; if($item['item_price'] < $item['item_list_price']) { $price_cell .= '$'.number_format($item['item_list_price'], 2).' '; } $price_cell .= '$'.number_format($item['item_price'], 2); $quantity = $item['item_qty']; $amount = $item['item_qty'] * $item['item_price']; if($item['item_action'] == 'return') { $quantity = -$quantity; $amount = - $amount; } $html .= ' '.$item_cell.'  '; if($type == 'admin') { $html .= ''.$status_form_table.''; } $html .= ' '.$price_cell.' '.$quantity.' $'.number_format($amount, 2).' '; if($type == 'admin') { $html .= '
'; } } $html .= ' '; return($html); } function insert_item($Designers, ItemAdmin $Item, $action, $price, $tax, $qty, $item_color_id, $color, $size_id, $size, $description, $final_sale, $list_price, $oi_status) { $oi_insert_fields = array( 'id' => NULL, 'order_id' => $this->id, 'item_id' => $Item->id, 'item_action' => $action, 'item_price' => $price, 'item_tax' => $tax, 'item_qty' => $qty, 'item_color' => $color, 'item_size' => $size, 'item_designer_name' => $Designers->get_name($Item->data['designer_id'], 'Order::insert_item'), 'item_name' => $Item->data['name'], 'item_description' => $description, 'final_sale' => $final_sale, 'item_list_price' => $list_price ); if($oi_id = Database::_insert(Config::$db_tables['order_items'], $oi_insert_fields, 'Order::insert_item')) { // inserts order_item_status record(s) - 1 record for each individual item if qty > 1 for($i=1;$i<=$qty;++$i) { $pick_up_date = ($oi_status == 'sto') ? "NOW()" : "''"; $this->insert_item_status($oi_id, $oi_status, $pick_up_date); } /////////////////////////////////////////////////////////////////////// // determine if this item - color and size combo - exists in item_breakdowns, // if not, insert it (unless dummy item) // if so, subtract or add item(s) from breakdown depending on action if(!$Item->is_dummy() && !$Item->is_gc()) { $adjust_qty = ($action == 'return') ? $qty : -$qty; // subtract from inventory for a purchase if(!$bd_id = $Item->get_bd_id($item_color_id, $size_id)) { $bd_id = $Item->insert_bd($adjust_qty, $item_color_id, $size_id); $msg = Config::$domain."/admin/items.hello?item_id=".$Item->data['id']."\nbd_id: $bd_id"; Utilities::notify(Config::$tech_email, "Item bd inserted", $msg); } else { $Item->adjust_bd_qty($adjust_qty, '', '', $bd_id); } } elseif($Item->is_dummy()) { // Utilities::notify(Config::$tech_email, "Dummy item entered", "https://".Config::$domain."/admin/items.hello?item_id=".$Item->data['id']); } /////////////////////////////////////////////////////////////////////// return($oi_id); } else { return(FALSE); } } function insert_item_status($order_item_id, $status, $deliv_date) { $ois_insert_fields = array( 'id' => NULL, 'order_item_id' => $order_item_id, 'order_item_status' => $status, 'order_item_delivery_date' => $deliv_date ); Database::_insert(Config::$db_tables['order_item_status'], $ois_insert_fields, 'Order::insert_item_status'); } function transfer_cart($Designers, $Cart, $Items, $Sizes, $Categories, $Promotion, $sale_is_taxable=FALSE) { //var_dump($Cart);exit(); $RS = $Cart->get_items_RS(); while($cart_row = $RS->FetchRow()) { $Item = new ItemAdmin($cart_row['item_id']); $Item->set_data(); $Item->set_colors(); $Item->set_sizes($Sizes); // tax will be 6% for ct res on anything other than clothing under $50 $item_tax = ($sale_is_taxable) ? $Item->get_tax_amount($Categories, $Promotion) : 0; $final_sale = 'no'; // never for web if(!$this->insert_item($Designers, $Item, 'purchase', $Item->get_web_price($Promotion), $item_tax, $cart_row['item_qty'], $cart_row['item_color_id'], $Item->colors[$cart_row['item_color_id']]['name'], $cart_row['size_id'], $Item->sizes[$cart_row['size_id']], $Item->data['description'], $final_sale, $Item->data['price_web'], 'tbp')) { Utilities::notify(Config::$tech_email, "ORDER ITEM INSERT FAILURE", "cart id: ".$Cart->id."\nitem id: ".$cart_row['item_id']."\nqty: ".$cart_row['item_qty']."\ncolor: ".$Item->colors[$cart_row['item_color_id']]['name']."\nsize: ".$Item->sizes[$cart_row['size_id']]); } } } function insert_transaction($total, $type='payment', $method='credit card', $notes='', $status='closed', $trans_date='NOW()') { // enter transaction $tr_ins_fields = array( 'id' => 'NULL', 'order_id' => $this->id, 'trans_dt' => $trans_date, 'trans_type' => $type, 'amount' => $total, 'method' => $method, 'notes' => $notes, 'status' => $status ); return(Database::_insert(Config::$db_tables['orders_transactions'], $tr_ins_fields, 'Order::insert_transaction')); } function insert_cc_transaction($order_transaction_id, $cc_number, $cc_exp, $cc_cvv2, $cc_name, $cc_street, $cc_postal, $cc_gateway='moneytree', $gateway_action='AUTH_CAPTURE', $gateway_trans_id='', $gateway_approval_code='', $gateway_raw_data='', $cc_type='', $gateway_ref_trans_id='', $status_cctr='CAPT', $capture_date='NOW()') { // $cc_exp ==> mmyy $cc_type = ($cc_number != '') ? Utilities::get_cc_type($cc_number) : $cc_type; $Encrypt = new Encryption(); //$cc_num_enc = (Config::$location == 'remote') ? $Encrypt->encrypt_data($cc_number) : $cc_number; $cc_num_enc = $Encrypt->encrypt_data($cc_number); $trcc_ins_fields = array( 'id' => 'NULL', 'transactions_id' => $order_transaction_id, 'cc_type' => $cc_type, 'cc_num_enc' => $cc_num_enc, 'cc_exp' => $cc_exp, 'cc_security_code' => $cc_cvv2, 'cc_name' => $cc_name, 'cc_street' => $cc_street, 'cc_postal' => $cc_postal, 'cc_gateway' => $cc_gateway, 'gateway_action' => $gateway_action, 'gateway_ref_trans_id' => $gateway_ref_trans_id, 'gateway_trans_id' => $gateway_trans_id, 'gateway_approval_code' => $gateway_approval_code, 'gateway_raw_data' => $gateway_raw_data, 'status_cctr' => $status_cctr, 'capture_date' => $capture_date ); //print_r($trcc_ins_fields); Database::_insert(Config::$db_tables['orders_transactions_cc'], $trcc_ins_fields, 'Order::insert_cc_transaction'); } function email_receipt_text($Template) { if(!isset($this->data)) { $this->get_data(); } if(!isset($Template->return_policy)) { $Template->set_return_policy(); } if($this->total_amount == 0) { $this->get_amounts(); } $text = "Thank you for your order at ".Config::$site_name."! We will ship your merchandise as soon as possible. If you have any questions, you can reach us at orders@".Config::$domain." or ".Config::$phone.". Your order information is below.\n\n***************************************************************\n".Utilities::formal_date(substr($this->data['order_dt'], 0, 10))."\nOrder#: ".$this->id."\n\nShip To:\n".$this->data['ship_name']."\n".$this->data['ship_address1']."\n".$this->data['ship_city'].", ".$this->data['ship_state']." ".$this->data['ship_postal']; if($this->data['ship_country'] != 'US') { $text .= "\n".$this->data['ship_country']; } $text .= "\n\nItems:"; if(!isset($this->items)) { $this->get_items(); } foreach($this->items as $item) { $item_text = $item['item_designer_name']. ' '.$item['item_name']; if($item['item_color'] != '') { $item_text .= ' ('.$item['item_color'].')'; } if($item['item_size'] != '') { $item_text .= ' ('.$item['item_size'].')'; } $price_cell = ''; if($item['item_price'] < $item['item_list_price']) { $price_cell .= '$'.number_format($item['item_list_price'], 2).' '; } $amount_text = '$'.number_format($item['item_qty'] * $item['item_price'], 2); $text .= "\n$item_text: ".$item['item_qty']." @ $".number_format($item['item_price'], 2)." = ".$amount_text; } $text .= "\n\nItems Total: $".number_format($this->items_amount,2); if($this->tax_amount > 0) { $text .= "\nCT Sales Tax (6.00%): $".number_format($this->tax_amount,2)."\n"; } $text .= "\nShipping (".$this->data['ship_method']."): "; $text .= ($this->ship_amount > 0) ? "$".number_format($this->ship_amount,2) : "FREE"; $text .= "\nOrder Total: $".number_format($this->total_amount,2)."\n"; if(!isset($this->transactions)) { $this->get_transactions(); } // get last 4 of cc foreach($this->transactions as $otr_id => $tr_info) { switch($tr_info['method']) { case 'credit card': $cc_last_4 = substr($tr_info['cc_number'], strlen($tr_info['cc_number'])-4); } } if(isset($cc_last_4)) { $text .= "\nPaid by: Credit Card ending with $cc_last_4\n"; } $text .= "***************************************************************\n\n---------------------------------------------------------------\n" .$Template->return_policy_email_text. "\n---------------------------------------------------------------\n\nThanks again for your order and please don't hesitate to contact us for any reason.\n\nTo join our email list go to www.".Config::$domain."/join\n\nTo view our recent arrivals check out www.".Config::$domain."/news often!\n\nBest Regards,\n\n".Config::$site_name."\n".Config::$store_address."\n".Config::$store_city.", ".Config::$store_state." ".Config::$store_zip."\n".Config::$phone."\n".Config::$site_info_email."\nwww.".Config::$domain; return($text); } function notes_form_html($Forms) { // notes and status form $html = '
Add note:
Order Status: '.$status_select = $Forms->generate_select_formfield_from_enum($select_name = "status", $field="order_status", $table="orders", $preselected=$this->data['order_status']).'
 
'; return($html); } function set_receipt_html($type='cust', $Contacts, $Template='', $Forms='', $POS='', $temp_script = FALSE) { $OrdersAdmin = new OrdersAdmin(); $this->receipt_html = ''; if($this->total_amount == 0) { $this->get_amounts(); } $odate = ($type == 'cust') ? Utilities::formal_date(substr($this->data['order_dt'], 0, 10)) : $this->data['order_dt']; if($type == 'cust') { if(!isset($Template->return_policy)) { $Template->set_return_policy(); } $this->receipt_html .= '
Thank you for your purchase!
Your order will be shipped as soon as possible. Please print this page for your records. If you have any questions, you can reach us at orders@'.Config::$domain.' or '.Config::$phone.'.
'; } else { // admin if($this->data['contact_id'] != 0) { $ContactRecord = Database::get_record_for_object($Contacts, $this->data['contact_id']); } $this->receipt_html .= ' '; $cust_cell = (isset($ContactRecord)) ? ''.$ContactRecord['name'].' ('.$ContactRecord['email'].' '.$this->data['ship_phone'].')' : 'not provided'; $this->receipt_html .= ' '; } if($type == 'admin') { $this->receipt_html .= ' '; if($this->data['notes'] != '') { $this->receipt_html .= ' '; } $this->receipt_html .= ' '; if($this->data['order_type'] == 'web') { $this->receipt_html .= ' '; if($this->data['ship_company'] != '') { $this->receipt_html .= ' '; } $this->receipt_html .= ' '; if($this->data['ship_country'] != 'US') { $this->receipt_html .= ' '; } } if(isset($Cust)) { $this->receipt_html .= ' '; } } // type == 'admin' $this->receipt_html .= ' '; if($type == 'admin' && $this->data['order_type'] == 'store') { if(!isset($POS) || $POS == '') { $POS = new POS(); } $this->receipt_html .= ' '; } $this->receipt_html .= ' '; if($type == 'admin' && $this->data['order_type'] == 'store' && $this->balance > 0) { // payment form $this->receipt_html .= '
'.$odate.'
Order #: '.$this->id.'
Order #: '.$this->id.' ('.ucwords($this->data['order_type']).' Order)'; if($this->data['order_status'] == 'canceled') { $this->receipt_html .= ' CANCELED'; } $this->receipt_html .= '     '.$odate.'
Customer: '.$cust_cell.'
'; if($this->data['order_type'] == 'web') { $this->receipt_html .= '
Salesperson: '.$OrdersAdmin->salesperson_select('salesperson1', $this->data['salesperson1']).'  '; if($_SESSION['level'] == 'owner' || $_SESSION['level'] == 'admin') { $this->receipt_html .= '
'; } } else { $this->receipt_html .= 'Salesperson(s): '.$this->data['salesperson1'].'   '.$this->data['salesperson2']; } $this->receipt_html .= '
Notes:'.$this->notes($this->data['notes']).'
'.$this->notes_form_html($Forms).'
Ship To:
'.$this->data['ship_name'].'   track customer through site
'.$this->data['ship_company'].'
'.$this->data['ship_address1'].'
'.$this->data['ship_city'].', '.$this->data['ship_state'].'  '.$this->data['ship_postal'].'
'.$this->data['ship_country'].'
Contact Information:
Phone: '.$ContactRecord['phone'].'
Email: '.$ContactRecord['email'].'
'.$this->items_html($type, $Forms).'
'.$this->amounts_html().'
'.$this->payments_html($type).'

Enter a Payment
$   '.$POS->method_select('payment_method', '- select payment method -', '').'   
'; } if($type == 'admin' && $this->data['order_type'] == 'web') { $this->receipt_html .= ' Print Packing Slip Print Mailing Label '; } $this->receipt_html .= ' '; if($type == 'cust') { $this->receipt_html .= '
'.$Template->return_policy_html.'
'; } } function update_trans_status($otr_id, $status) { $upd = "UPDATE ".Config::$db_tables['orders_transactions']." SET status = '$status' WHERE id='$otr_id' LIMIT 1"; Database::ado_execute_query($upd); } function method_data_to_trans_data($trans_method, $otr_id, &$trans_data) { // should be called when getting trans data for a cc, gc, or sc method trans - adds all orders_transactions_{trans_method} to array $table = 'orders_transactions_'.$trans_method; if($method_trans_data = Database::ado_get_row("SELECT * FROM ".Config::$db_tables[$table]." WHERE transactions_id='$otr_id'", "Order::method_data_to_trans_data")) { foreach($method_trans_data as $key=>$val) { if($key == 'id') { $tableKey = $table.'_id'; $trans_data[$tableKey] = $val; } elseif($trans_method == 'cc' && $key == 'cc_num_enc') { $E = new Encryption(); $trans_data['cc_number'] = $E->decryptSNAFU_data($method_trans_data['cc_num_enc']); } else { $trans_data[$key] = $val; } } } } function get_transactions() { if(!isset($this->total_amount)) { $this->get_amounts(); } $this->transactions = array(); $sel = "SELECT * FROM ".Config::$db_tables['orders_transactions']." WHERE order_id = $this->id ORDER BY trans_dt"; $RS = Database::ado_execute_query($sel, 'Order::get_transactions'); while($row = $RS->FetchRow()) { if($row['status'] == 'closed') { if($row['trans_type'] == 'payment') { $this->payments_amount += $row['amount']; } elseif($row['trans_type'] == 'refund') { $this->refunds_amount += $row['amount']; } } else { if($row['trans_type'] == 'payment') { $this->pending_payments_amount += $row['amount']; } elseif($row['trans_type'] == 'refund') { // not sure there would ever be a pending refund $this->pending_refunds_amount += $row['amount']; } } $this->transactions[$row['id']] = $row; switch($row['method']) { // some repetition below case 'credit card': $this->method_data_to_trans_data('cc', $row['id'], $this->transactions[$row['id']]); break; case 'gift certificate': $this->method_data_to_trans_data('gc', $row['id'], $this->transactions[$row['id']]); break; case 'store credit': $this->method_data_to_trans_data('sc', $row['id'], $this->transactions[$row['id']]); break; default: }// switch } } function payments_html($type='cust') { // type is cust or admin (cust only applies to web orders) if(!isset($this->total_amount)) { $this->get_amounts(); } $display_balance = $this->total_amount; // the balance to display after each transaction row for store orders $html = ' '; if(round($this->balance) != 0 && ($this->data['order_type'] == 'store' || $type == 'admin') ) { $html .= ' '; } if($this->data['order_type'] == 'store') { $html .= ' '; } else { if($type == 'admin') // no row for cust - just 'Paid by x4111 in transactions' { $html .= ' '; } } foreach($this->transactions as $otr_id => $tr_info) { $display_date = Utilities::informal_date(substr($tr_info['trans_dt'],0,10)); if($this->data['order_type'] == 'store') { $method_cell = ucwords($tr_info['method']); if($tr_info['trans_type'] == 'refund') { $method_cell .= ' REFUND'; if($tr_info['status'] == 'pending') { $method_cell .= ' PENDING'; } else { $display_balance += $tr_info['amount']; } } else { if($tr_info['status'] == 'pending') { $method_cell .= ' PENDING'; } else { $display_balance -= $tr_info['amount']; } } $html .= ' '; } else // web order { if($type == 'cust' && $tr_info['method'] == 'credit card') { $html .= ' '; } elseif($type == 'admin') { //print_r($tr_info); if($tr_info['method'] == 'credit card') { $method_cell = $tr_info['cc_number'].'
Exp (mmyy): '.$tr_info['cc_exp'].'
CVV2: '.$tr_info['cc_security_code'].'
Name on Card: '.$tr_info['cc_name'].'
Address: '.$tr_info['cc_street'].'
Zip Code: '.$tr_info['cc_postal'].'
trans id: '.$tr_info['gateway_trans_id']; if($tr_info['gateway_ref_trans_id'] != '') { $method_cell .= '
ref trans id: '.$tr_info['gateway_ref_trans_id']; } $status_cell = $tr_info['status_cctr']; switch($tr_info['status_cctr']) { case 'AUTH': $actions_cell = ' $'; break; case 'CAPT': $status_cell .= '
'.$tr_info['capture_date']; $actions_cell = ' $'; break; default: $actions_cell = ' '; } if($_SESSION['level'] != 'owner' && $_SESSION['level'] != 'admin') { $actions_cell = ' '; } } else { $method_cell = ' '; $status_cell = ' '; $actions_cell = ' '; } $html .= ' '; } } } if($this->data['order_type'] == 'web' && $type == 'admin' && ($_SESSION['level'] == 'owner' || $_SESSION['level'] == 'admin') ) { // new transaction form - for a new cc charge $html .= '
Current Balance: $'.number_format($this->balance, 2).'
Payments:
Date Method Amount Balance
Transactions:
'.$display_date.' '.$method_cell.' $'.number_format($tr_info['amount'],2).' $'.number_format($display_balance,2).'
Paid by credit card ending in '.substr($tr_info['cc_number'], strlen($tr_info['cc_number'])-4).'
'.$display_date.': '.ucwords($tr_info['trans_type']).' $'.number_format($tr_info['amount'],2).' '.$method_cell.' '.$status_cell.' '.$actions_cell.'
Charge Credit Card for $
   cc exp:   cc security code:   cc name:   cc street:   cc postal:
'; } $html .= '
'; return($html); } function amounts_html() { $html = ' '; if($this->tax_amount != 0) { $html .= ' '; } // shipping - display for all web orders and store orders with non-zero ship amount if($this->data['order_type'] == 'web' || $this->ship_amount != 0) { $shipping_amount_display = ($this->ship_amount > 0) ? '$'.number_format($this->ship_amount, 2) : 'FREE'; $html .= ' '; } $html .= '
Items Total:   $'.number_format($this->items_amount, 2).'
CT Sales Tax (6.00%):   $'.number_format($this->tax_amount, 2).'
Shipping ('.$this->data['ship_method'].'):   '.$shipping_amount_display.'
Total:   $'.number_format($this->total_amount, 2).'
'; return($html); } function send_email_receipt($Contact, $Template) { $to = array($Contact->data["email"]); $subject = "Your HelloBoutique.com Order"; $body = $this->email_receipt_text($Template); $from = ""; //default $from_name = "HelloBoutique.com"; $bcc = array(); foreach(Config::$owner_emails as $oe) { $bcc[] = $oe; } $bcc[] = Config::$product_advisor_email; $reply_to = "orders@".Config::$domain; //$img_arr = array('logo'=>Config::$path_to_www.'/images/logo.jpg'); Utilities::phpmailer_email($to, $subject, $body, $from, $from_name, "", $bcc, $reply_to, "", FALSE); } function get_num_payment_transactions() { $num = 0; if(!isset($this->transactions)) { $this->get_transactions(); } foreach($this->transactions as $otr_id=>$trans_info) { if($trans_info['trans_type'] == 'payment') { ++$num; } } return($num); } } ?>