sales amount function __Construct($contact_id) { $this->contact_id = $contact_id; $this->des_sales = array(); } function get_orders($OrdersAdmin, $order_dt_start='', $by_des=false, $sort_des_sales='amount', $bgcolor="#FFFFFF") { $RS = $OrdersAdmin->get_contact_orders($this->contact_id, $order_dt_start); $this->sales_total = 0; $this->sales_num = 0; $this->sales_html = ' '; while($order = $RS->FetchRow()) { //echo '

New Order: '.$order['id'].'
'; ++$this->sales_num; if($this->sales_num == 1) { $this->last_purchase_date = substr($order['order_dt'], 0, 10); } $OrderAdmin = new OrderAdmin($order['id']); $OrderAdmin->get_amounts(); $this->sales_total += $OrderAdmin->total_amount; //echo 'Total: $'.$this->sales_total.'

'; if($order['order_type'] == 'web') { $this->cust_type = ($this->cust_type == 'store') ? 'both' : 'web'; } else { $this->cust_type = ($this->cust_type == 'web') ? 'both' : 'store'; } // the notes column will either display the notes (for sales before 7/1 - no receipt number and no items, or the list of designers of items purchased if($order['order_dt'] < '2005-07-01') { $notes_field = $order['notes']; } else { $notes_field = ''; foreach($OrderAdmin->items as $oi) { if($notes_field != '') { $notes_field .= ', '; } $notes_field .= $oi['item_designer_name'].' '; $notes_field .= ($oi['item_name'] != 'dummy item') ? $oi['item_name'] : $oi['item_description']; } } $this->sales_html .= ' '; if($by_des) { $OrderAdmin->get_items(); foreach($OrderAdmin->items as $oi_id => $oi_info) { $item_amount = ($oi_info['item_designer_name'] == 'return') ? -$oi_info['item_price']*$oi_info['item_qty'] : $oi_info['item_price']*$oi_info['item_qty']; if(array_key_exists($oi_info['item_designer_name'], $this->des_sales)) { $this->des_sales[$oi_info['item_designer_name']] += $item_amount; } else { $this->des_sales[$oi_info['item_designer_name']] = $item_amount; } } } }// while if(isset($this->des_sales) && count($this->des_sales) > 0) { // sort if($sort_des_sales == 'amount') { arsort($this->des_sales); } else { // name ksort($this->des_sales); } } $this->sales_html .= '
Order # Date Total Notes
'.$order['id'].' '.substr($order['order_dt'], 0, 10).' $'.number_format($OrderAdmin->total_amount,2); if(round($OrderAdmin->balance) != 0) { $this->sales_html .= ' BALANCE: $'.number_format($OrderAdmin->balance, 2).''; } $this->sales_html .= ' '.$notes_field.'
'; $this->sales_avg = ($this->sales_num == 0) ? 0 : round($this->sales_total / $this->sales_num, 0); } function open_close_links($qs_nav) { $open_close = (isset($_GET['open']) && $_GET['open'] == $this->contact_id) ? '-' : '+'; return($open_close); } } ?>