<?php
namespace WpBookingHotelAdminWooPanel\app\models;
defined('_WPBOOKINGHOTEL_EXEC') or die;

use WpBookingHotel\Factory;
use WpBookingHotel\Mvc\Model\ModelForm;
use WpBookingHotel\Form\Form;
use WpBookingHotel\Mvc\Model\ModelList;
use WpBookingHotel\Registry\Registry;
class CustomersModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "customers";
    /**
     * @var string
     */
    public $table_name = "customer";
    public function getList()
    {
        $list = parent::getList(); // TODO: Change the autogenerated stub
        foreach ($list as $item) {
            $item->full_name = "{$item->first_name} {$item->last_name}";
        }
        return $list;
    }
    public function get_list_customer_in_year()
    {
        $now = Factory::getDate();
        $now1 = $now->modify('-12 month');
        $query = $this->_db->getQuery(true);
        $query->select('customer1.*')
            ->select('MONTH(customer1.created_date) AS month')
            ->from($this->getTableName('customer') . ' AS customer1')
            ->where('customer1.created_date>=' . $query->quote($now1->toSql()));
        $list = $this->_db->setQuery($query)->loadObjectList();
        foreach ($list as $item) {
            $item->full_name = "{$item->first_name} {$item->last_name}";
        }
        return $list;
    }


}
