Esempio n. 1
0
 /**
  * Order info: total price, quantity, num of items, currency,
  * shipping price, grand total price
  * 
  * @param type $id
  * @return type
  */
 public function order_info($id = false)
 {
     $out = array();
     if ($item = \Order\Model_Order::find_one_by_id($id)) {
         if (!empty($item->products)) {
             $currency = $item->currency;
             $sum_products = count($item->products);
             $sum_products_quantity = 0;
             $total_price = 0;
             foreach ($item->products as $key => $product) {
                 $total_price += $product->sub_total_with_tax;
             }
             $out = array('total_price' => $total_price, 'quantity' => $sum_products_quantity, 'num_items' => $sum_products, 'currency' => $currency, 'shipping_price' => $item->shipping_price, 'grand_total_price' => $total_price + $item->shipping_price);
             if ($item->is_sample_order == 1) {
                 $out = array('total_price' => $item->total_price, 'quantity' => $sum_products_quantity, 'num_items' => $sum_products, 'currency' => $currency, 'shipping_price' => $item->shipping_price, 'grand_total_price' => $item->total_price + $item->shipping_price);
             }
         }
     }
     return $out;
 }
    ?>
                        </a>
                    </td>
                </tr>

            <?php 
    $subtotal += $item->subtotal;
}
?>

            <?php 
if (!empty($items)) {
    ?>
                
                <?php 
    $order_details = \Order\Model_Order::order_info($order->id);
    ?>
                
                <tr class="order_total">
                    <td class="order_invisible">&nbsp;</td>
                    <td class="order_invisible">&nbsp;</td>
                    <td class="order_invisible" colspan="2" align="right">
                        <?php 
    if (isset($panel_title)) {
        ?>
                            <a href="<?php 
        echo \Uri::create('admin/order/update/' . (isset($duplicate_order->id) ? $duplicate_order->id : $order->id));
        ?>
" class="btn btn-mini btn-primary">
                                Full Edit Order <?php 
        echo isset($duplicate_order->number) ? $duplicate_order->number : $order->number;
Esempio n. 3
0
 /**
  * Catch IPN response from PayPal
  *
  * @access  public
  * @return  void
  */
 public function action_ipn()
 {
     \Package::load('paypalipn');
     $post = \Input::post();
     $admin_email = '*****@*****.**';
     if (isset($post['invoice']) || is_numeric($post['invoice'])) {
         if ($order = \Order\Model_Order::find_one_by_id($post['invoice'])) {
             $order_info = $this->order_info($post['invoice']);
             //$validate_order['mc_currency'] =  strtoupper($order['currency']);
             $validate_order['mc_currency'] = "AUD";
             $validate_order['mc_gross'] = $order_info['grand_total_price'];
             $response = \PaypalIpn::forge()->validate($validate_order);
             $response_check = $response !== false;
             //                @mail($admin_email, \Config::get('site_title', 'Giant Invitation Australia') . ' Pre response ' . $response['invoice'],
             //                    'Order id : ' . $response['invoice'] . "\n" .
             //                    'Response:' . print_r($response, true) . "\n" .
             //                    'Check:' . $response_check);
             $payment = \Payment\Model_Payment::forge();
             /*
             [mc_gross] => 527.00
             [invoice] => 9
             [protection_eligibility] => Eligible
             [address_status] => confirmed
             [item_number1] =>
             [tax] => 0.00
             [item_number2] =>
             [payer_id] => 2AY578XVRY42G
             [address_street] => 1 Main St
             [payment_date] => 05:19:51 Dec 20, 2012 PST
             [payment_status] => Completed
             [charset] => windows-1252
             [address_zip] => 95131
             [mc_shipping] => 0.00
             [mc_handling] => 0.00
             [first_name] => Djordje
             [mc_fee] => 20.90
             [address_country_code] => US
             [address_name] => Djordje Dimitrijev
             [notify_version] => 3.7
             [custom] =>
             [payer_status] => verified
             [business] => s01_1354717870_biz@eximius-solutions.com
             [address_country] => United States
             [num_cart_items] => 2
             [mc_handling1] => 0.00
             [mc_handling2] => 0.00
             [address_city] => San Jose
             [verify_sign] => Amjz0My6wXvXmjP5pfTStQO3QZ2QA4.Ti6ln42PKcmRKuS-ZegoVx6nF
             [payer_email] => b01_1354717574_per@eximius-solutions.com
             [mc_shipping1] => 0.00
             [mc_shipping2] => 0.00
             [tax1] => 0.00
             [tax2] => 0.00
             [txn_id] => 3AR12649JA9996934
             [payment_type] => instant
             [last_name] => Dimitrijev
             [address_state] => CA
             [item_name1] => Fujiyama
             [receiver_email] => s01_1354717870_biz@eximius-solutions.com
             [item_name2] => Musala
             [payment_fee] =>
             [quantity1] => 2
             [quantity2] => 1
             [receiver_id] => W4MYKU8N4SVHS
             [txn_type] => cart
             [mc_gross_1] => 398.00
             [mc_currency] => EUR
             [mc_gross_2] => 129.00
             [residence_country] => US
             [test_ipn] => 1
             [transaction_subject] => Shopping CartFujiyamaMusala
             [payment_gross] =>
             [ipn_track_id] => 72c4d71c8638a
             */
             if ($response !== false) {
                 $json_response = json_encode($response);
                 $payment->order_id = $response['invoice'];
                 $payment->total_price = $response['mc_gross'];
                 $payment->method = 'paypal';
                 $payment->status = $response['payment_status'];
                 $payment->response = $json_response;
                 if (isset($response['pending_reason'])) {
                     $payment->status_detail = $response['pending_reason'];
                 }
                 if (strtolower($response['payment_status']) == 'completed') {
                     // Send email
                     /*$emailer = new \PaymentProccess\PaymentEmailer($order);
                       $emailer->send();*/
                     $emailer = new \Autorespondertrigger\Trigger();
                     $emailer->sendOrderPaymentReceivedPaypalCredit($order);
                     $order->total_price = $order_info['total_price'];
                     $order->paymentmethod = 'N/A';
                     if (isset($order->payments[0]->method)) {
                         $order->paymentmethod = $order->payments[0]->method;
                     }
                     // Create redemption code ( if order is sample order - this will be checked in RedemptionCodeSaverClass)
                     $redemptionCodeSaver = new \DiscountCodeApplier\RedemptionCodeSaver($order);
                     $redemptionCodeSaver->save();
                 } else {
                     logger(\Fuel::L_INFO, 'PayPal IPN - Pending order. Order ID: ' . $response['invoice'] . '. - ' . $json_response);
                     @mail($admin_email, \Config::get('site_title', 'Giant Invitation Australia') . ' | PayPal IPN - Pending order. Order ID: ' . $response['invoice'], 'PayPal IPN - Pending order. Order ID: ' . $response['invoice'] . "\n" . print_r($response, true));
                 }
             } else {
                 $payment->order_id = $post['invoice'];
                 $payment->total_price = $post['mc_gross'];
                 $payment->method = 'paypal';
                 $payment->status = 'Pending';
                 $payment->response = json_encode($post);
                 // Log order as failed
                 logger(\Fuel::L_INFO, 'PayPal IPN - Failed order. Order ID: ' . $response['invoice'] . '. - ' . $json_response);
                 @mail($admin_email, \Config::get('site_title', 'Giant Invitation Australia') . ' | PayPal IPN - Failed order. Order ID: ' . $response['invoice'], 'PayPal IPN - Failed order. Order ID: ' . $response['invoice'] . "\n" . print_r($response, true));
             }
             // Save payment to database
             try {
                 $payment->save();
             } catch (\Database_Exception $e) {
                 logger(\Fuel::L_INFO, 'PayPal IPN - error during inserting data into the database. Order ID: ' . $response['invoice'] . '. - ' . $json_response);
                 @mail($admin_email, \Config::get('site_title', 'My Shortlist') . ' | PayPal IPN - DB error. Order ID: ' . $response['invoice'], 'PayPal IPN - error during inserting data into the database. Order ID: ' . $response['invoice'] . "\n" . print_r($response, true));
             }
         } else {
             logger(\Fuel::L_INFO, 'PayPal IPN - error. There is no order with ID: ' . $post['invoice'] . '. - ' . json_encode($post));
             @mail($admin_email, \Config::get('site_title', 'My Shortlist') . ' | PayPal IPN - error. There is no order with ID: ' . $post['invoice'], 'PayPal IPN - there is no order with ID: ' . $post['invoice'] . "\n" . print_r($post, true));
         }
     } else {
         logger(\Fuel::L_INFO, 'PayPal IPN - error. Missing Order ID. - ' . json_encode($post));
         @mail($admin_email, \Config::get('site_title', 'My Shortlist') . ' | PayPal IPN - error. Missing Order ID.', 'PayPal IPN - Missing Order ID.' . "\n" . print_r($post, true));
     }
 }
Esempio n. 4
0
 public function action_create_order()
 {
     if (!\Input::is_ajax()) {
         die;
     }
     // We need order ID - save order if not exists
     $order_id = \Session::get('order.id', false);
     if (!is_numeric($order_id)) {
         $order = \Order\Model_Order::forge(array('finished' => 0));
         $order->save();
         \Session::set('order.id', $order->id);
     }
     echo $order_id;
 }
                <th scope="col" class="noresize">Date Added</th>
                <th scope="col" class="center" style="width: 40px;">Edit</th>
            </tr>
        </thead>
        <tbody>

            <?php 
// var_dump($items);
?>
            
            <?php 
foreach ($items as $item) {
    ?>

                <?php 
    $item_info = \Order\Model_Order::order_info($item->id);
    ?>
                <tr>
                    <td><?php 
    echo $item->purchase_number;
    ?>
</td>
                    <td>
                        <?php 
    $names = array('Red Eleven Slim Fit Jacket', 'Bellfield Checked Shirt', 'Brogues In multi Color', 'Dark Jacket');
    echo $names[(int) rand(0, 3)];
    ?>
                    </td> 
                    <td title="<?php 
    echo date('d/m/Y \\a\\t H:i:s', $item->created_at);
    ?>
 protected function save_order()
 {
     if (!$this->check_logged()) {
         \Messages::error('You must be logged in if you want to continue with your order.');
         \Response::redirect(\Uri::create('order/checkout/address'));
     }
     // Save order
     $user = false;
     $order = false;
     $items = \Cart::items();
     if (\Sentry::check()) {
         $user = \Sentry::user();
     }
     if (\Input::post() && $items && $user) {
         $group_id = $user['groups'][0]['id'];
         $item_with_discount = array();
         foreach ($items as $item) {
             $id = $item->get('id');
             $product_groups = \Product\Model_Product_To_Groups::find_by_product_id($item->get('id'));
             foreach ($product_groups as $group) {
                 $all_discounts = \Product\Model_Group_Discounts::find_by(array('user_group_id' => $group_id, 'product_group_id' => $group->group_id), null, null, null);
                 foreach ($all_discounts as $discount) {
                     $discount = (int) $item_with_discount[$id]['discount'] + $discount->discount;
                     $sub_total = $item->totalPrice(true) - (int) $discount / $item->totalPrice(true) * 100;
                     $item_with_discount[$id] = array('product_group_id' => $group->product_id, 'user_group_id' => $group->group_id, 'discount' => $discount, 'sub_total' => $sub_total);
                 }
             }
             $item_with_discount['total_discount'] = (int) $item_with_discount['total_discount'] + (int) $item_with_discount[$id]['total_discount'];
             $item_with_discount['total_price'] = (double) $item_with_discount['total_price'] + (double) $item_with_discount[$id]['sub_total'];
         }
         // check for a valid CSRF token
         if (!\Security::check_token()) {
             \Messages::error('CSRF attack or expired CSRF token.');
             \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost')));
         }
         try {
             // Update or create order
             if (is_numeric(\Session::get('order.id'))) {
                 $order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
             }
             if (!$order) {
                 $order = \Order\Model_Order::forge();
             }
             $shipping_price = $order->shipping_price(null, null, true);
             $metadata = $user['metadata'];
             if ($billing = \Arr::filter_prefixed($metadata, 'shipping_')) {
                 foreach ($billing as $key => $value) {
                     $order->{$key} = $metadata[$key];
                     unset($metadata[$key]);
                 }
             }
             foreach ($metadata as $key => $value) {
                 $order->{$key} = $value;
             }
             $order->email = $user->get('email');
             $order->user_id = $user->get('id');
             $order->status = 'Pending';
             $order->discount_amount = $item_with_discount['total_discount'];
             //\Cart::getTotal('price');
             $order->total_price = $item_with_discount['total_price'];
             //\Cart::getTotal('price');
             $order->finished = 1;
             $order->guest = $metadata['guest'] ? 1 : 0;
             $order->accepted = $metadata['master'] == 1 ? 1 : 0;
             $order->credit_account = $metadata['credit_account'] == 1 ? 1 : 0;
             $order->shipping_price = $shipping_price;
             // Save order, add products to order products
             if ($order->save()) {
                 foreach ($items as $item) {
                     $product_data = null;
                     if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
                         $product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
                     }
                     if ($product_data) {
                         $order_products = \Order\Model_Products::forge();
                         $order_products->order_id = $order->id;
                         $order_products->title = $product->title;
                         $order_products->code = $product_data['code'];
                         $order_products->price = $item->singlePrice(true);
                         $order_products->price_type = $product_data['price_type'];
                         $order_products->quantity = $item->get('quantity');
                         $order_products->product_id = $product->id;
                         $order_products->artwork_required = $product->artwork_required;
                         $order_products->artwork_free_over = $product->artwork_free_over;
                         $order_products->subtotal = $item_with_discount[$item->get('id')]['sub_total'];
                         //$item->totalPrice(true);
                         $order_products->attributes = json_encode(\Product\Model_Attribute::get_combination($item->get('attributes')));
                         if (!empty($product->categories)) {
                             $categories = array();
                             foreach ($product->categories as $category) {
                                 $categories[] = $category->title;
                             }
                             if ($categories) {
                                 $order_products->product_category = implode(',', $categories);
                             }
                         }
                         $order_products->save();
                         // Find artworks
                         if ($unique_id = $item->get('unique_id')) {
                             if ($artworks = \Order\Model_Artwork::find(array('where' => array('unique_id' => $unique_id, 'order_id' => $order->id)))) {
                                 $ysi = \Yousendit\Base::forge();
                                 // Artworks (update, delete)
                                 foreach ($artworks as $artwork) {
                                     // Remove deleted artwork
                                     if ($artwork->deleted_at > 0) {
                                         $ysi->delete_artwork($artwork->file_id);
                                         $artwork->delete();
                                     } else {
                                         $artwork->order_product_id = $order_products->id;
                                         $artwork->save();
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($order) {
                 return $order;
             } else {
                 return false;
             }
         } catch (\Database_Exception $e) {
             // show validation errors
             \Messages::error('There was an error while trying to save your order.');
             // Uncomment lines below to show database errors
             $errors = $e->getMessage();
             \Messages::error($errors);
             \Response::redirect(\Uri::create('order/checkout/cost'));
         }
         return false;
     }
 }
Esempio n. 7
0
 public static function credit_account($user_id = null, $new_amount = 0)
 {
     if (is_numeric($user_id) && \Sentry::user_exists((int) $user_id)) {
         $user = \Sentry::user((int) $user_id);
     } else {
         $user = \Sentry::user();
     }
     $out['credit'] = false;
     if ($user->get('metadata.credit_account') != 1) {
         return $out;
     }
     $out['credit'] = true;
     if ($month = $user->get('metadata.purchase_limit_period')) {
         $start = strtotime(date('m-01-Y', strtotime("-{$month} month")));
         $orders_total = 0;
         $orders = \Order\Model_Order::find(array('where' => array(array('created_at', '>', $start), 'user_id' => $user->get('id'), 'finished' => 1)));
         if ($orders) {
             foreach ($orders as $order) {
                 $orders_total += $order->total_price + $order->shipping_price;
             }
         }
         if ($orders_total + $new_amount > $user->get('metadata.purchase_limit_value')) {
             $out['over_limit'] = true;
             $out['over_limit_amount'] = $orders_total + $new_amount - $user->get('metadata.purchase_limit_value');
         } else {
             $out['over_limit'] = false;
             $out['over_limit_amount'] = 0;
         }
         $out['orders_total'] = $orders_total;
         $out['limit'] = $user->get('metadata.purchase_limit_value');
         $out['period'] = $user->get('metadata.purchase_limit_period');
     }
     if (is_numeric(\Session::get('order.id'))) {
         $order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
         if (isset($order)) {
             $new_amount = $order->total_price + $order->shipping_price - $order->discount_amount;
         }
     }
     $out['current_total'] = $new_amount;
     return $out;
 }
Esempio n. 8
0
 public function action_accept_order($id = null)
 {
     // Get order
     $order = \Order\Model_Order::find_one_by_id($id);
     if (!$order) {
         \Messages::error('Order with that ID does not exist or has been deleted.');
         \Response::redirect(\Uri::front_create('user/account/orders'));
     }
     // Get current user
     $user = \Sentry::user();
     $master_user = false;
     if (isset($user['metadata']['master']) && $user['metadata']['master']) {
         $master_user = true;
     }
     if (!$master_user) {
         \Messages::error("You don't have permssion for this action.");
         \Response::redirect(\Uri::front_create('user/account'));
     }
     try {
         $order->accepted = 1;
         $order->save();
         \Messages::success('Order successfully updated.');
         \Response::redirect(\Input::referrer(\Uri::front_create('user/account')));
     } catch (\Database_Exception $e) {
         \Messages::error('There was an error while trying to update order.');
     }
 }
Esempio n. 9
0
 public function action_clear_discount()
 {
     $order = \Order\Model_Order::forge();
     if (is_numeric(\Session::get('order.id'))) {
         $order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
         $order->set(array('id_discount' => NULL, 'discount_amount' => 0));
         $order->save();
     }
 }
Esempio n. 10
0
 public function get_search_sales_by_month()
 {
     $years = \Order\Model_Order::find(array('where' => array(array('total_price', 'is not', NULL))));
     $year_list = array();
     $month_list = array();
     foreach ($years as $year) {
         $year = date('Y', $year->created_at);
         if (!in_array($year, $year_list)) {
             $year_list += array($year => $year);
         }
     }
     $get_first_year = $year_list;
     rsort($get_first_year);
     krsort($year_list);
     if (\Input::get()) {
         if (\Input::get('year') != 'select') {
             $choose_year = \Input::get('year') ? \Input::get('year') : $get_first_year[0];
             for ($i = 1; $i <= 12; $i++) {
                 $timestamp = mktime(0, 0, 1, $i, 1, date("Y"));
                 $month = date("F", $timestamp);
                 $results = \DB::query('SELECT sum(total_price) as total_amount from orders where year(FROM_UNIXTIME(created_at)) = ' . $choose_year . ' and month(FROM_UNIXTIME(created_at)) = ' . $i)->execute();
                 array_push($month_list, array('month' => array('name' => $month, 'amount' => number_format($results[0]['total_amount'], 2))));
             }
         }
     }
     return array('items' => $month_list, 'years' => $year_list);
 }
Esempio n. 11
0
 public function action_pdf($order_id = false)
 {
     if (!($order = \Order\Model_Order::find_one_by_id($order_id))) {
         \Messages::error('There was an error while trying to create PDF for order ID: ' . $order_id);
         \Response::redirect(\Input::referrer(\Uri::create('admin/order/list')));
     }
     $pdf = \Pdf\Pdf::forge('tcpdf')->init('P', 'mm', 'A4', true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Cool Kids Rooms');
     $pdf->SetTitle('Invoice');
     $pdf->SetSubject('Invoice');
     //$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     // remove default header/footer
     $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // set font
     //$pdf->SetFont('times', 'BI', 20);
     // add a page
     $pdf->AddPage();
     // ---------------------------------------------------------
     $content['content']['data'] = $order;
     $html = \Theme::instance()->view($this->view_dir . 'invoice/order', $content, false);
     // output the HTML content
     $pdf->writeHTML($html, true, false, true, false, '');
     // ---------------------------------------------------------
     //Close and output PDF document
     $pdf->Output('Invoice Order ' . $order_id . '.pdf', 'I');
 }
Esempio n. 12
0
 public function action_clear_cart()
 {
     $items = \Cart::items();
     $order = null;
     if (is_numeric(\Session::get('order.id'))) {
         $order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
     }
     if ($order) {
         $order->delete();
     }
     if ($items) {
         foreach ($items as $item) {
             // Find artworks
             if ($unique_id = $item->get('unique_id')) {
                 if ($artworks = \Order\Model_Artwork::find(array('where' => array('unique_id' => $unique_id, 'order_id' => \Session::get('order.id'))))) {
                     $ysi = \Yousendit\Base::forge();
                     // Artworks (update, delete)
                     foreach ($artworks as $artwork) {
                         // Remove deleted artwork
                         if ($artwork->file_id) {
                             $ysi->delete_artwork($artwork->file_id);
                         }
                     }
                 }
             }
         }
     }
     // Delete order & cart session
     \Session::delete('order.id');
     \Cart::clear();
     \Messages::info('Your cart is empty.');
     if (\Input::is_ajax()) {
         echo \Messages::display();
         exit;
     } else {
         \Response::redirect(\Input::referrer(\Uri::create('order/checkout/address')));
     }
 }
Esempio n. 13
0
 public function get_search_items2($user_id = false)
 {
     // Override group_id if its a search
     $user_id = \Input::get('user_id', $user_id);
     if ($user_id && \Sentry::user_exists((int) $user_id)) {
         $user = \Sentry::user((int) $user_id);
     }
     $items = \Order\Model_Order::find(function ($query) {
         if (isset($user)) {
             $query->where('user_id', $user->id);
         }
         $query->order_by('main_number', 'desc');
         $query->order_by('id', 'asc');
     });
     foreach (\Input::get() as $key => $value) {
         if (!empty($value) || $value == '0') {
             switch ($key) {
                 case 'title':
                     foreach ($items as $number => $item) {
                         $full_name = $item->first_name . ' ' . $item->last_name;
                         if (stripos($item->company, $value) === false) {
                             if (stripos($full_name, $value) === false) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'email':
                     foreach ($items as $number => $item) {
                         if (stripos($item->email, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'custom_order_status':
                     if (array_key_exists($value, \Config::get('details.status', array()))) {
                         foreach ($items as $number => $item) {
                             if ($item->status != $value) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'order_total_from':
                     is_numeric($value) or $value = 0;
                     foreach ($items as $number => $item) {
                         $item_details = \Order\Model_Order::order_info($item->id);
                         if ($item_details['total_price'] < $value) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'order_total_to':
                     is_numeric($value) or $value = 0;
                     foreach ($items as $number => $item) {
                         $item_details = \Order\Model_Order::order_info($item->id);
                         if ($item_details['total_price'] > $value) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'date_from':
                     if ($date = strtotime($value)) {
                         foreach ($items as $number => $item) {
                             if ($item->created_at < $date) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'date_to':
                     if ($date = strtotime($value)) {
                         foreach ($items as $number => $item) {
                             if ($item->created_at > $date) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'sch_from':
                     if ($date = strtotime($value)) {
                         foreach ($items as $number => $item) {
                             if ($item->sch_delivery < $date) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'sch_to':
                     if ($date = strtotime($value)) {
                         foreach ($items as $number => $item) {
                             if ($item->sch_delivery > $date) {
                                 unset($items[$number]);
                             }
                         }
                     }
                     break;
                 case 'status':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (stripos($item->status, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'invoice_status':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (stripos($item->invoice_status, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'delivery_status':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (stripos($item->delivery_status, $value) === false) {
                             unset($items[$number]);
                         }
                     }
                     break;
                 case 'user_group':
                     foreach ($items as $number => $item) {
                         if ($value == 'false') {
                             break;
                         }
                         if (!\Sentry::user_exists((int) $item->user_id) || !\Sentry::user((int) $item->user_id)->in_group($value)) {
                             unset($items[$number]);
                         }
                     }
                     break;
             }
         }
     }
     // Reset to empty array if there are no result found by query
     if (is_null($items)) {
         $items = array();
     }
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     return array('items' => $items, 'pagination' => $pagination);
 }
 public function get_search_sales_by_date()
 {
     $years = \Order\Model_Order::find(array('where' => array(array('total_price', 'is not', NULL))));
     $year_list = array();
     foreach ($years as $year) {
         $year = date('Y', $year->created_at);
         if (!in_array($year, $year_list)) {
             $year_list += array($year => $year);
         }
     }
     $get_first_year = $year_list;
     rsort($get_first_year);
     krsort($year_list);
     $choose_year = \Input::get('year') ? \Input::get('year') : $get_first_year[0];
     $month_list = array();
     for ($i = 0; $i < 12; $i++) {
         $timestamp = mktime(0, 0, 1, date("m") + $i, date("d"), date("Y"));
         $month = date("F", $timestamp);
         $month_list += array($i + 1 => $month);
     }
     $choose_month = \Input::get('month') ? \Input::get('month') : 1;
     $number_of_days = cal_days_in_month(null, $choose_month, $choose_year);
     $items = array();
     if (\Input::get()) {
         for ($i = 1; $i <= $number_of_days; $i++) {
             $results = \DB::query('SELECT sum(total_price) as total_price from orders where year(FROM_UNIXTIME(created_at)) = ' . $choose_year . ' and month(FROM_UNIXTIME(created_at)) = ' . $choose_month . ' and day(FROM_UNIXTIME(created_at)) = ' . $i)->execute();
             array_push($items, array('amount' => $results[0]['total_price'], 'date' => $i . '/' . $choose_month . '/' . $choose_year));
         }
     }
     return array('months' => $month_list, 'years' => $year_list, 'dates' => $items);
 }