
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Saleslog_model extends CI_Model {

public function __construct() {
parent::__construct();
}
 function getsalelog($datefrom,$dateto, $paymenttype) {

  $table_name = "TICKETS";
        $this->db->select("TICKETS.TICKETID AS RECEIPT,RECEIPTS.DATENEW AS DATE,CUSTOMERS.NAME AS CUSTOMER ,PAYMENTS.PAYMENT AS PAYMENTTYPE,(PAYMENTS.TOTAL)AS TOTAL")->from($table_name);
        if ($datefrom && $dateto) {
            $this->db->where("RECEIPTS.DATENEW >=", Date($datefrom));
            $this->db->where("RECEIPTS.DATENEW <=", Date($dateto));
        } 
          else if ($datefrom) {
            $this->db->where("RECEIPTS.DATENEW >=", Date($datefrom));
        }
            else if ($dateto) {
            $this->db->where("RECEIPTS.DATENEW <=", Date($dateto));
        }
         if ($paymenttype) {
            $this->db->where("PAYMENTS.PAYMENT", $paymenttype);
        }

         $this->db->join('RECEIPTS','RECEIPTS.ID=TICKETS.ID','LEFT');
          $this->db->join('TICKETLINES','TICKETLINES.TICKET=TICKETS.ID','LEFT');
         $this->db->join('PAYMENTS','RECEIPTS.ID=PAYMENTS.RECEIPT','LEFT');
          $this->db->join('CUSTOMERS','TICKETS.CUSTOMER=CUSTOMERS.ID','LEFT');
           $this->db->group_by('RECEIPTS.DATENEW');
        $rows = $this->db->get()->result();
     
        return $rows;
    }

    //a.e
}


