Exemple #1
0
 public function request($type, $start, $end)
 {
     $tree = new stdClass();
     switch ($type) {
         case 'sales':
             $tree = array();
             if (empty($end)) {
                 $end = date('Y-m-d H:i:s', (int) gmdate('U'));
             }
             $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $start . '\'' . ' AND transaction_date <= \'' . $end . '\'' . ' ORDER BY transaction_date ASC';
             $this->db->setQuery($query);
             $entries = xJ::getDBArray($this->db);
             if (empty($entries)) {
                 echo json_encode($tree);
                 exit;
             }
             $historylist = array();
             $groups = array();
             foreach ($entries as $id) {
                 $entry = new logHistory();
                 $entry->load($id);
                 $entry->amount = AECToolbox::correctAmount($entry->amount);
                 $refund = false;
                 if (is_array($entry->response) && !empty($entry->response)) {
                     $filter = array('new_case', 'subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel', 'Pending', 'Denied');
                     foreach ($entry->response as $v) {
                         if (in_array($v, $filter)) {
                             continue 2;
                         } elseif ($v == 'refund' || $v == 'Reversed' || $v == 'Refunded') {
                             $refund = true;
                         }
                     }
                 } else {
                     continue;
                 }
                 $pgroups = ItemGroupHandler::parentGroups($entry->plan_id);
                 if (empty($pgroups[0])) {
                     $pgroups[0] = 0;
                 }
                 if (!in_array($pgroups[0], $groups)) {
                     $groups[] = $pgroups[0];
                 }
                 $sale = new stdClass();
                 $sale->id = $id;
                 //$sale->invoice	= $entry->invoice_number;
                 $sale->date = $entry->transaction_date;
                 //$sale->datejs	= date( 'F d, Y H:i:s', strtotime( $entry->transaction_date ) );
                 $sale->plan = $entry->plan_id;
                 $sale->group = $pgroups[0];
                 $sale->amount = $refund ? -$entry->amount : $entry->amount;
                 $tree[] = $sale;
             }
             break;
     }
     echo json_encode($tree);
     exit;
 }
Exemple #2
0
 public function Action()
 {
     if (empty($_POST['start_date'])) {
         return null;
     }
     $db = JFactory::getDBO();
     $start_timeframe = $_POST['start_date'] . ' 00:00:00';
     if (empty($end)) {
         $end = date('Y-m-d', (int) gmdate('U'));
     }
     $end_timeframe = $end . ' 23:59:59';
     $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $start_timeframe . '\'' . ' AND transaction_date <= \'' . $end_timeframe . '\'' . ' ORDER BY transaction_date ASC';
     $db->setQuery($query);
     $entries = xJ::getDBArray($db);
     if (empty($entries)) {
         return "nothing to list";
     }
     $historylist = array();
     $groups = array();
     foreach ($entries as $id) {
         $entry = new logHistory();
         $entry->load($id);
         $refund = false;
         if (is_array($entry->response)) {
             $filter = array('new_case', 'subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel', 'Pending', 'Denied');
             $refund = false;
             foreach ($entry->response as $v) {
                 if (in_array($v, $filter)) {
                     continue 2;
                 } elseif ($v == 'refund' || $v == 'Reversed' || $v == 'Refunded') {
                     $refund = true;
                 }
             }
         }
         $date = date('Y-m-d', strtotime($entry->transaction_date));
         $pgroups = ItemGroupHandler::parentGroups($entry->plan_id);
         if (!in_array($pgroups[0], $groups)) {
             $groups[] = $pgroups[0];
         }
         if (!isset($historylist[$date])) {
             $historylist[$date] = array('amount' => null, 'groups' => null);
         }
         if ($refund) {
             $historylist[$date]['amount'] -= (double) $entry->amount;
             $historylist[$date]['groups'][$pgroups[0]]--;
         } else {
             $historylist[$date]['amount'] += (double) $entry->amount;
             $historylist[$date]['groups'][$pgroups[0]]++;
         }
     }
     foreach ($historylist as $date => $entry) {
         ksort($historylist[$date]['groups']);
     }
     $return = "";
     $return .= '<table style="background-color: fff; width: 30%; margin: 0 auto; text-align: center !important; font-size: 180%;">';
     $groupnames = array();
     foreach ($groups as $group) {
         $groupnames[$group] = ItemGroupHandler::groupName($group);
     }
     $closer = 0;
     $incomplete = false;
     foreach ($historylist as $date => $history) {
         if (date('D', strtotime($date)) == 'Mon') {
             $week = array();
         } elseif (!isset($week)) {
             $week = array();
             $incomplete = true;
         }
         $return .= '<tr style="border-bottom: 2px solid #999 !important; height: 2em;">';
         $return .= '<td title="Date" style="text-align: left !important; color: #aaa;">' . $date . '</td>';
         $return .= '<td style="width: 5em;">&nbsp;</td>';
         foreach ($groups as $group) {
             if (empty($history['groups'][$group])) {
                 $count = 0;
             } else {
                 $count = $history['groups'][$group];
             }
             $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>';
             if (isset($week)) {
                 $week['groups'][$group] += $count;
             }
         }
         if (isset($week)) {
             $week['amount'] += $history['amount'];
         }
         $return .= '<td style="width: 5em;">&nbsp;</td>';
         $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($history['amount']) . '</td>';
         $return .= '</tr>';
         $return .= '<tr style="height: 1px; background-color: #999;">';
         $return .= '<td colspan="' . (count($groups) + 4) . '"></td>';
         $return .= '</tr>';
         $closer = 0;
         if (date('D', strtotime($date)) == 'Sun') {
             $return .= '<tr ' . ($incomplete ? 'title="Incomplete!"' : '') . 'style="border-bottom: 2px solid #999 !important; height: 2em; background-color: #ddd;">';
             $return .= '<td style="text-align: left !important; color: #aaa;">' . ($incomplete ? '(Week)' : 'Week') . '</td>';
             $return .= '<td style="width: 5em;">&nbsp;</td>';
             foreach ($groups as $group) {
                 if (empty($week['groups'][$group])) {
                     $count = 0;
                 } else {
                     $count = $week['groups'][$group];
                 }
                 if ($incomplete) {
                     $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">(' . $count . ')</td>';
                 } else {
                     $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>';
                 }
             }
             $return .= '<td style="width: 5em;">&nbsp;</td>';
             if ($incomplete) {
                 $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">(' . AECToolbox::correctAmount($week['amount']) . ')</td>';
             } else {
                 $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($week['amount']) . '</td>';
             }
             $return .= '</tr>';
             $return .= '<tr style="height: 1px; background-color: #999;">';
             $return .= '<td colspan="' . (count($groups) + 4) . '"></td>';
             $return .= '</tr>';
             $closer = 1;
             $incomplete = false;
         }
     }
     if (!$closer) {
         $return .= '<tr style="border-bottom: 2px solid #999 !important; height: 2em; background-color: #ddd;">';
         $return .= '<td title="Date" style="text-align: left !important; color: #aaa;">(Week)</td>';
         $return .= '<td style="width: 5em;">&nbsp;</td>';
         foreach ($groups as $group) {
             if (empty($week['groups'][$group])) {
                 $count = 0;
             } else {
                 $count = $week['groups'][$group];
             }
             $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>';
         }
         $return .= '<td style="width: 5em;">&nbsp;</td>';
         $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($week['amount']) . '</td>';
         $return .= '</tr>';
         $return .= '<tr style="height: 1px; background-color: #999;">';
         $return .= '<td colspan="' . (count($groups) + 4) . '"></td>';
         $return .= '</tr>';
         $closer = 1;
     }
     $return .= '</table><br /><br />';
     return $return;
 }
 public function copy()
 {
     $pid = $this->id;
     $this->id = 0;
     $this->storeload();
     $parents = ItemGroupHandler::parentGroups($pid, 'group');
     foreach ($parents as $parentid) {
         ItemGroupHandler::setChild($this->id, $parentid, 'group');
     }
 }