items)) { $this->get_items(); } foreach($this->items as $oi_id => $oi_info) { //print_r($oi_info['status']); // note items will have multiple status rows if qty > 1 foreach($oi_info['status'] as $ois_info) { if($ois_info['order_item_status'] == 'ret') { return(TRUE); } } } return(FALSE); } function get_initial_ship_date() { // returns least order_items_status.order_item_delivery_date or false if all are 0 if(!isset($this->items)) { $this->get_items(); } $initial = FALSE; foreach($this->items as $oi_id => $oi_info) { //print_r($oi_info['status']); // note items will have multiple status rows if qty > 1 foreach($oi_info['status'] as $ois_info) { if($ois_info['order_item_delivery_date'] != '0000-00-00' && ( !$initial || Utilities::date_compare($ois_info['order_item_delivery_date'], $initial) < 0) ) { $initial = $ois_info['order_item_delivery_date']; } } } return($initial); } function any_item_shipped() { // checks if an item status is set to 'snc' or 'shp' or 'ret' for this order if(!isset($this->items)) { $this->get_items(); } foreach($this->items as $oi_id => $oi_info) { //print_r($oi_info['status']); // note items will have multiple status rows if qty > 1 foreach($oi_info['status'] as $ois_info) { if($ois_info['order_item_status'] == 'snc' || $ois_info['order_item_status'] == 'shp' || $ois_info['order_item_status'] == 'ret') { return(TRUE); } } } return(FALSE); } function update_trans_amount($otr_id, $amount) { $upd = "UPDATE ".Config::$db_tables['orders_transactions']." SET amount = '$amount' WHERE id='$otr_id' LIMIT 1"; Database::ado_execute_query($upd); } function update_capture_date($orders_transactions_cc_id, $captDate) { $upd = "UPDATE ".Config::$db_tables['orders_transactions_cc']." SET capture_date = '$captDate' WHERE id='$orders_transactions_cc_id' LIMIT 1"; //echo $upd; Database::ado_execute_query($upd); } function update_trans_dt($otr_id, $dt) { $upd = "UPDATE ".Config::$db_tables['orders_transactions']." SET trans_dt = '$dt' WHERE id='$otr_id' LIMIT 1"; Database::ado_execute_query($upd); } function get_transaction($otr_id) { if($trans_data = Database::ado_get_row("SELECT * FROM ".Config::$db_tables['orders_transactions']." WHERE id='$otr_id'")) { switch($trans_data['method']) { case 'credit card': $this->method_data_to_trans_data('cc', $otr_id, $trans_data); break; case 'gift certificate': $this->method_data_to_trans_data('sc', $otr_id, $trans_data); break; case 'store credit': $this->method_data_to_trans_data('gc', $otr_id, $trans_data); break; } } else { return(FALSE); } return($trans_data); } function delete_store_credits() { Database::ado_execute_query("DELETE FROM ".Config::$db_tables['store_credits']." WHERE order_id='".$this->id."'"); } function delete_gc($order_item_id) { $del = "DELETE FROM ".Config::$db_tables['gift_certificates']." WHERE order_item_id='$order_item_id'"; Database::ado_execute_query($del); } function delete_oistatus($order_item_id) { Database::ado_execute_query("DELETE FROM ".Config::$db_tables['order_item_status']." WHERE order_item_id='$order_item_id'"); } function delete_items() { Database::ado_execute_query("DELETE FROM ".Config::$db_tables['order_items']." WHERE order_id='".$this->id."'"); } function delete_cc_trans($otr_id) { Database::ado_execute_query("DELETE FROM ".Config::$db_tables['orders_transactions_cc']." WHERE transactions_id='$otr_id'"); } function delete_gc_trans($otr_id) { Database::ado_execute_query("DELETE FROM ".Config::$db_tables['orders_transactions_gc']." WHERE transactions_id='$otr_id'"); } function delete_sc_trans($otr_id) { Database::ado_execute_query("DELETE FROM ".Config::$db_tables['orders_transactions_sc']." WHERE transactions_id='$otr_id'"); } function delete_transactions() { Database::ado_execute_query("DELETE FROM ".Config::$db_tables['orders_transactions']." WHERE order_id='".$this->id."'"); } function delete_record() { Database::ado_execute_query("DELETE FROM ".Config::$db_tables['orders']." WHERE id='".$this->id."' LIMIT 1"); } function _delete($Items, $Sizes) { $remove = $_GET['remove']; $this->delete_store_credits(); $this->get_items(); foreach($this->items as $oitem) { $ItemAdmin = new ItemAdmin($oitem['item_id']); if($ItemAdmin->is_gc()) { $this->delete_gc($oitem['id']); } else { if(!$ItemAdmin->is_dummy()) { $adjust_qty = ($oitem['item_action'] == 'return') ? -$oitem['item_qty'] : $oitem['item_qty']; // add back to inventory if purchase $ItemAdmin->adjust_bd_qty($adjust_qty, $ItemAdmin->get_item_color_id($oitem['item_color']), $ItemAdmin->get_size_id($oitem['item_size'], $Sizes)); } } $this->delete_oistatus($oitem['id']); } $this->delete_items(); // remove transaction records for this order $this->get_transactions(); foreach($this->transactions as $otr_id => $tr) { if($tr['method'] == 'credit card') { $this->delete_cc_trans($otr_id); } elseif($tr['method'] == 'gift certificate') { $this->delete_gc_trans($otr_id); } elseif($tr['method'] == 'store credit') { $this->delete_sc_trans($otr_id); } $this->delete_transactions(); } $this->delete_record(); return(TRUE); } function notes_html() { $html = ''; $notes = array_reverse(explode('|', $this->data['notes'])); foreach($notes as $note) { $html .= '
  '; $html .= $note; } return($html); } function get_gc_number_for_item($oi_id) { return(Database::ado_get_one("SELECT gc_number FROM ".Config::$db_tables['gift_certificates']." WHERE order_item_id='$oi_id'", "OrderAdmin::get_gc_number_for_item")); } function _update($fields) { $where_fields = array('id' => $this->id); Database::_update(Config::$db_tables['orders'], $fields, $where_fields, 1, "OrderAdmin::_update"); } function notes($db_notes) { $html = ''; $notes = array_reverse(explode('|', $db_notes)); $i = 0; foreach($notes as $note) { ++$i; $html .= '
  '; $html .= $note; } return($html); } function get_oi_data_for_ois($oi_id) { if(!isset($this->items)) { $this->get_items(); } foreach($this->items as $oi) { //print_r($oi); if($oi['id'] == $oi_id) { return($oi); } } } function update_oi_status($Items, $Sizes, $ois_id, $status, $delivery_date, $return_date='') { // if setting an item to 'ret' inc qty in bd - need to instantiate $ItemAdmin object // note: the details page is only set up to allow this for a web sale, store returns are entered as a new sale if($status == 'ret' || $status == 'cxc' || $status == 'cxs') { // adjust inventory $ois_data = $this->get_ois_data($ois_id); if($oi = $this->get_oi_data_for_ois($ois_data['order_item_id'])) { $IA = new ItemAdmin($oi['item_id']); $IA->adjust_bd_qty($oi['item_qty'], $IA->get_item_color_id($oi['item_color']), $IA->get_size_id($oi['item_size'], $Sizes)); } } if(trim($delivery_date) == '') { $delivery_date = '0000-00-00'; } $upd = "UPDATE ".Config::$db_tables['order_item_status']." SET order_item_status='$status', order_item_delivery_date='$delivery_date', order_item_return_date='$return_date' WHERE id='$ois_id' LIMIT 1"; //echo $upd; Database::ado_execute_query($upd, "OrderAdmin::update_oi_status"); } function get_oi_statuses($oi_id) { return(Database::ado_execute_query("SELECT * FROM ".Config::$db_tables['order_item_status']." WHERE order_item_id=$oi_id", "OrderAdmin::get_oi_statuses")); } function apply_final_layaway_payment($Items, $Sizes) { // update item statuses from lay to sto and order status to closed // what if an item has a different status? - do not change cancelled items - cxc or cxs if(!isset($this->items)) { $this->get_items(); } foreach($this->items as $oi) { foreach($oi['status'] as $ois_id => $oi_status) { if($oi_status != 'cxc' && $oi_status != 'cxs') { $this->update_oi_status($Items, $Sizes, $ois_id, 'sto', 'NOW()'); } } } $this->_update(array('order_status'=>'closed')); } function packing_slip($ois_ids) { // plenty of duplication below:::::::::: $Template = new Template(); $Template->set_return_policy(); ////////////////////////////////////////////// // determine ship amount - if this is the 2nd or greater shipment for this order then shipping will be free. and method will be ground $statsel = "SELECT b.order_item_delivery_date FROM ".Config::$db_tables['order_items']." a, ".Config::$db_tables['order_item_status']." b WHERE a.id=b.order_item_id AND a.order_id='".$this->id."'"; // don't include the items for this packing slip foreach($ois_ids as $ois => $on_off) { if($on_off == 'on') { $statsel .= " AND b.id != $ois"; } } //echo $statsel; $statRS = Database::ado_execute_query($statsel); while($statrow = $statRS->FetchRow()) { if($statrow['order_item_delivery_date'] != '0000-00-00' && Utilities::date_in_past($statrow['order_item_delivery_date'])) { //print_r($statrow);exit(); $this->data['ship_amount'] = 0; $ship_method = 'Ground'; break; } } if(!isset($ship_method)) { $ship_method = $this->data['ship_method']; } ////////////////////////////////////////////// // get cc # from transactions // to do if(Config::$location != 'local') { //require_once('../../zz_encryption.php'); //$o_enc = new encryption; //$this->info['bill_cc_number'] = $o_enc->decryptSNAFU_data($this->info['bill_cc_number'], $ek); } $html = ' '; if($this->data['ship_company'] != '') { $html .= ' '; } $html .= ' '; if($this->data['ship_address2'] != '') { $html .= ' '; } $html .= ' '; //$sel = "SELECT * FROM ".Config::$db_tables['order_items']." WHERE order_id='".$this->info['id']."'"; //echo $sel; // get items being shipped based on $ois_ids :: note that if 2 or more ids point to same order_item then 2 or more of that item are being shipped // set up an array of packing slip items $ps_items = array(); foreach($ois_ids as $ois => $on_off) { if($on_off == 'on') { $sel = "SELECT a.order_item_status as status, b.* FROM ".Config::$db_tables['order_item_status']." a, ".Config::$db_tables['order_items']." b WHERE a.order_item_id=b.id AND a.id='$ois'"; $oisRow = Database::ado_get_row($sel); //echo $sel; //print_r($oisRow); //echo '

'; // make sure status is either snc or shp if($oisRow['status'] != 'snc' && $oisRow['status'] != 'shp' && $oisRow['status'] != 'drp') { echo '
error: status should either be drp, snc, or shp
'; } else { // either add item to array or if the order_item is already in ps_items then just increment the qty $addNewLine = TRUE; $ps_counter = 0; foreach($ps_items as $item) { if($item['order_item_id'] == $oisRow['order_item_id']) { ++$ps_items[$ps_counter]['item_qty']; $addNewLine = FALSE; } ++$ps_counter; } if($addNewLine) { $item_name = ($oisRow['item_name'] == 'dummy item') ? $oisRow['item_description'] : $oisRow['item_name']; $ps_items[] = array( 'order_item_id' => $oisRow['id'], 'item_name' => $item_name, 'item_color' => $oisRow['item_color'], 'item_size' => $oisRow['item_size'], 'item_price' => $oisRow['item_price'], 'item_unit_tax' => $oisRow['item_tax'], 'designer' => $oisRow['item_designer_name'], 'item_qty' => 1 ); } } } } //exit(); //$rs = Database::ado_execute_query($sel); //while($item = $rs->FetchRow()) $ps_items_amount = 0; $ps_tax_amount = 0; foreach($ps_items as $item) { $item_text = $item['item_name']; if($item['item_color'] != '') { $item_text .= ' ('.$item['item_color'].')'; } if($item['item_size'] != '') { $item_text .= ' ('.$item['item_size'].')'; } $item_amount = $item['item_qty'] * $item['item_price']; $item_tax = $item['item_qty'] * $item['item_unit_tax']; $ps_items_amount += $item_amount; $ps_tax_amount += $item_tax; $html .= ' '; } // END WHILE $ps_total = $ps_items_amount + $ps_tax_amount + $this->data['ship_amount']; // AMOUNTS ROWS $html .= ' '; if($ps_tax_amount > 0) { $html .= ' '; } $ship_amount_display = ($this->data['ship_amount'] == 0) ? 'FREE' : '$'.number_format($this->data['ship_amount'],2); $html .= ' '; $html .= ' '; /* $cc_last4 = substr($this->info['bill_cc_number'], strlen($this->info['bill_cc_number'])-4); $html .= ' */ $html .= ' '; // look for backordered items $sel = "SELECT * FROM ".Config::$db_tables['order_items']." WHERE order_id=$this->id"; $iRS = Database::ado_execute_query($sel); $bck_items = array(); $bck_items_count = 0; // tracks # lines of backordered items (qty > 1 doesn't matter) while($irow = $iRS->FetchRow()) { $qty = $irow['item_qty']; $price = $irow['item_price']; $stRS = Database::ado_execute_query("SELECT * FROM ".Config::$db_tables['order_item_status']." WHERE order_item_id='".$irow['id']."'"); // may get more than 1 if qty > 1 while($strow = $stRS->FetchRow()) { $item_bck_count = 0; // how many of this order item are backorderd (in case qty > 1) $status = $strow['order_item_status']; if($status == 'bck') { ++$item_bck_count; if($item_bck_count == 1) { ++$bck_items_count; $item_name = ($irow['item_name'] == 'dummy item') ? $irow['item_description'] : $irow['item_name']; $bck_items[] = array( 'order_item_id' => $order_item_id, 'item_name' => $item_name, 'item_color' => $irow['item_color'], 'item_size' => $irow['item_size'], 'item_price' => $irow['item_price'], 'designer' => $irow['item_designer_name'], 'item_qty' => 1 ); } else { // increment backordered qty ++$bck_items[$bck_items_count]['item_qty']; } } } } if(count($bck_items) > 0) { $html .= ' '; foreach($bck_items as $item) { $item_text = $item['item_name']; if($item['item_color'] != '') { $item_text .= ' ('.$item['item_color'].')'; } if($item['item_size'] != '') { $item_text .= ' ('.$item['item_size'].')'; } $item_amount = $item['item_qty'] * $item['item_price']; $html .= ' '; } // END WHILE $html .= ' '; } $html .= ' '; $html .= '
 
Order #: '.$this->id.'
Order Date: '.substr($this->data['order_dt'], 5, 2).'/'.substr($this->data['order_dt'], 8, 2).'/'.substr($this->data['order_dt'], 0, 4).'
 
Ship To:
'.strtoupper($this->data['ship_name']).'
'.strtoupper($this->data['ship_company']).'
'.strtoupper($this->data['ship_address1']).'
'.strtoupper($this->data['ship_address2']).'
'.strtoupper($this->data['ship_city']).' '.strtoupper($this->data['ship_state']).' '.strtoupper($this->data['ship_postal']).' '.strtoupper($this->data['ship_country']).'
 
Items in this package

Designer Item Price Quantity Total
'.$item['designer'].' '.$item_text.'   $'.$item['item_price'].' '.$item['item_qty'].' $'.number_format($item_amount,2).'

Shipment Subtotal:   $'.number_format($ps_items_amount,2).'
CT Sales Tax:     $'.number_format($ps_tax_amount,2).'
Shipping ('.$ship_method.'):      '.$ship_amount_display.'
Shipment Total:   $'.number_format($ps_total, 2).'
Paid By:
Credit Card ending with '.$cc_last4.'
Thanks for your order!
 
Backordered Items *

Designer Item Quantity
'.$item['designer'].' '.$item_text.' '.$item['item_qty'].'
 
* Backordered items are shipped as soon as possible. You are not charged for an item until it is shipped. You are only charged shipping on the first delivery of your order.
'.$Template->return_policy_html.'
Questions?
Email orders@helloboutique.com or call 203-562-0204.
'; return($html); } function mailing_label() { $html = '
1090 Chapel Street
New Haven, CT  06510








Ship To:     '; if($this->data['ship_address2'] != '') { $html .= ' '; } $html .= ' '; if($this->data['ship_country'] != 'US') { $html .= ' '; } $html .= '
'.strtoupper($this->data['ship_name']).'
'.strtoupper($this->data['ship_address1']).'
'.strtoupper($this->data['ship_address2']).'
'.strtoupper($this->data['ship_city']).', '.strtoupper($this->data['ship_state']).'  '.$this->data['ship_postal'].'
'.strtoupper($this->data['ship_country']).'
'; return($html); } } ?>