<?php
namespace TourOperatorProAdminWoopanel\app\models;
defined('_TOUROPERATOR_EXEC') or die;

use TourOperatorPro\Factory;
use TourOperatorPro\Mvc\Model\ModelForm;
use TourOperatorPro\Form\Form;
use TourOperatorPro\Mvc\Model\ModelList;
use TourOperatorPro\Registry\Registry;
class CustomersModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "customers";
    /**
     * @var string
     */
    public $table_name = "customer";
    public function getList()
    {
        $db=Factory::getDBO();
        $query=$this->getListQuery();

        return $db->setQuery($query)->loadObjectList();
    }
    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;
    }


}
