ok
Direktori : /home2/selectio/www/mm-tailor-billing/app/controllers/ |
Current File : /home2/selectio/www/mm-tailor-billing/app/controllers/Welcome.php |
<?php defined('BASEPATH') or exit('No direct script access allowed'); class Welcome extends MY_Controller { public function __construct() { parent::__construct(); if (!$this->loggedIn) { redirect('login'); } if (version_compare($this->Settings->version, '4.0.14', '<=')) { $this->load->model('db_update'); $this->db_update->update(); } $this->load->model('welcome_model'); if ($register = $this->site->registerData($this->session->userdata('user_id'))) { $register_data = ['register_id' => $register->id, 'cash_in_hand' => $register->cash_in_hand, 'register_open_time' => $register->date, 'store_id' => $register->store_id]; $this->session->set_userdata($register_data); } } public function disabled() { $this->data['error'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('error'); $this->data['page_title'] = lang('disabled_in_demo'); $bc = [['link' => '#', 'page' => lang('disabled_in_demo')]]; $meta = ['page_title' => lang('disabled_in_demo'), 'bc' => $bc]; $this->page_construct('disabled', $this->data, $meta); } public function index() { $this->data['customers'] = $this->welcome_model->getAllCustomers(); $this->data['error'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('error'); $this->data['topProducts'] = $this->welcome_model->topProducts(); $this->data['chartData'] = $this->welcome_model->getChartData(); $this->data['page_title'] = lang('dashboard'); $bc = [['link' => '#', 'page' => lang('dashboard')]]; $meta = ['page_title' => lang('dashboard'), 'bc' => $bc]; $this->page_construct('dashboard', $this->data, $meta); } // Get Products Starts Here public function get_products($store_id) { //$category = $this->input->get('category') ? $this->input->get('category') : NULL; $category = 5; $types = $this->input->get('types') ? $this->input->get('types') : NULL; $this->load->library('datatables'); if ($this->Admin) { $this->datatables->select($this->db->dbprefix('products') . '.id as pid, ' . $this->db->dbprefix('products') . '.image as image, ' . $this->db->dbprefix('products') . '.code as code, ' . $this->db->dbprefix('products') . '.name as pname, type, ' . $this->db->dbprefix('categories') . ".name as cname, psq.quantity, tax, tax_method, cost, (CASE WHEN psq.price > 0 THEN psq.price ELSE {$this->db->dbprefix('products')}.price END) as price, barcode_symbology, units.name as unit_name", false); } else { $this->datatables->select($this->db->dbprefix('products') . '.id as pid, ' . $this->db->dbprefix('products') . '.image as image, ' . $this->db->dbprefix('products') . '.code as code, ' . $this->db->dbprefix('products') . '.name as pname, type, ' . $this->db->dbprefix('categories') . ".name as cname, psq.quantity, tax, tax_method, (CASE WHEN psq.price > 0 THEN psq.price ELSE {$this->db->dbprefix('products')}.price END) as price, barcode_symbology, units.name as unit_name", false); } $this->datatables->from('products') ->join('categories', 'categories.id=products.category_id', 'left') ->join('units', 'units.id=products.units', 'left') ->join('product_store_qty', 'product_store_qty.product_id=products.id', 'left') ->join("( SELECT * from {$this->db->dbprefix('product_store_qty')} WHERE store_id = {$store_id}) psq", 'products.id=psq.product_id', 'left') ->where('product_store_qty.store_id', $store_id) /*->where('products.category_id', '5')*/ ->group_by('products.id'); $this->datatables->add_column('Actions', "<div class='text-center'><div class='btn-group'><a href='" . site_url('products/view/$1') . "' title='" . lang('view') . "' class='tip btn btn-primary btn-xs' data-toggle='ajax'><i class='fa fa-file-text-o'></i></a><a href='" . site_url('products/single_barcode/$1') . "' title='" . lang('print_barcodes') . "' class='tip btn btn-default btn-xs' data-toggle='ajax-modal'><i class='fa fa-print'></i></a> <a href='" . site_url('products/single_label/$1') . "' title='" . lang('print_labels') . "' class='tip btn btn-default btn-xs' data-toggle='ajax-modal'><i class='fa fa-print'></i></a> <a class='tip image btn btn-primary btn-xs' id='$4 ($3)' href='" . base_url('uploads/$2') . "' title='" . lang('view_image') . "'><i class='fa fa-picture-o'></i></a> <a href='" . site_url('products/edit/$1') . "' title='" . lang('edit_product') . "' class='tip btn btn-warning btn-xs'><i class='fa fa-edit'></i></a> <a href='" . site_url('products/delete/$1') . "' onClick=\"return confirm('" . lang('alert_x_product') . "')\" title='" . lang('delete_product') . "' class='tip btn btn-danger btn-xs'><i class='fa fa-trash-o'></i></a></div></div>", 'pid, image, code, pname, barcode_symbology'); $this->datatables->add_column('Sales_Product', "<div class='text-center'><span class='btn btn-primary btn-xs sales' id='$1'>Sales Product</span></div>", 'pid, image, code, pname, barcode_symbology'); $this->datatables->unset_column('pid')->unset_column('barcode_symbology'); if($category) { $this->datatables->where('category_id', $category); } if($types) { $this->datatables->where('type', $types); } /*$this->datatables->where('category_id', $category);*/ echo $this->datatables->generate(); } // Get Products Endsss Here // Get Sales Starts Here public function get_sales() { $start_date = $this->input->get('start_date') ? $this->input->get('start_date') : NULL; $end_date = $this->input->get('end_date') ? $this->input->get('end_date') : NULL; $unit_status = $this->input->get('unit_status') ? $this->input->get('unit_status') : NULL; $this->load->library('datatables'); if ($this->db->dbdriver == 'sqlite3') { $this->datatables->select("tec_sales.id, DATE_FORMAT(date, '%d-%m-%Y') as date, customer_name, customer_phone_no, hold_ref, total, total_tax, total_discount, grand_total, paid, status, DATE_FORMAT(deliver_date, '%d-%m-%Y') as deliver_date, DATE_FORMAT(due_date, '%d-%m-%Y') as due_date, DATE_FORMAT(sale_date, '%d-%m-%Y') as sale_date, total_items,unit_process_status, (SELECT FORMAT((SUM(tec_sale_items.quantity)),0) from tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id=tec_products.id where tec_sale_items.sale_id=tec_sales.id and tec_products.pant_shirt_category=1) as pant_counts, (SELECT FORMAT((SUM(tec_sale_items.quantity)),0) from tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id=tec_products.id where tec_sale_items.sale_id=tec_sales.id and tec_products.pant_shirt_category=2) as shirt_counts,sells,(grand_total-(paid+discount)) as balance, discount, CONCAT(IFNULL(dc_prefix, ''), hold_ref) AS New_DC_number, CASE WHEN (SELECT FORMAT(SUM(tec_sale_items.quantity), 0) FROM tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id = tec_products.id WHERE tec_sale_items.sale_id = tec_sales.id AND tec_products.pant_shirt_category = 2) IS NULL THEN 0 ELSE (SELECT FORMAT(SUM(tec_sale_items.quantity), 0) FROM tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id = tec_products.id WHERE tec_sale_items.sale_id = tec_sales.id AND tec_products.pant_shirt_category = 2) END AS shirt_count, CASE WHEN (SELECT FORMAT(SUM(tec_sale_items.quantity), 0) FROM tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id = tec_products.id WHERE tec_sale_items.sale_id = tec_sales.id AND tec_products.pant_shirt_category = 1) IS NULL THEN 0 ELSE (SELECT FORMAT(SUM(tec_sale_items.quantity), 0) FROM tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id = tec_products.id WHERE tec_sale_items.sale_id = tec_sales.id AND tec_products.pant_shirt_category = 1) END AS pant_count, IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign'))) as neww_musthafa_cutting, IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=2 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=2 and tec_work_units.assign_or_not='assign'))) as neww_musthafa_stitching, (SELECT phone FROM tec_customers WHERE tec_sales.customer_id=tec_customers.id) as customer_phone, (SELECT phone FROM tec_customers WHERE tec_sales.customer_id=tec_customers.id) as customer_phone"); } else { $this->datatables->select("tec_sales.id, DATE_FORMAT(date, '%d-%m-%Y') as date, customer_name, customer_phone_no, hold_ref, total, total_tax, total_discount, grand_total, paid, status, DATE_FORMAT(deliver_date, '%d-%m-%Y') as deliver_date, DATE_FORMAT(due_date, '%d-%m-%Y') as due_date, DATE_FORMAT(sale_date, '%d-%m-%Y') as sale_date, total_items,unit_process_status, (SELECT FORMAT((SUM(tec_sale_items.quantity)),0) from tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id=tec_products.id where tec_sale_items.sale_id=tec_sales.id and tec_products.pant_shirt_category=1) as pant_counts, (SELECT FORMAT((SUM(tec_sale_items.quantity)),0) from tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id=tec_products.id where tec_sale_items.sale_id=tec_sales.id and tec_products.pant_shirt_category=2) as shirt_counts, sells,(grand_total-(paid+discount)) as balance, discount, CONCAT(IFNULL(dc_prefix, ''), hold_ref) AS New_DC_number, CASE WHEN (SELECT FORMAT(SUM(tec_sale_items.quantity), 0) FROM tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id = tec_products.id WHERE tec_sale_items.sale_id = tec_sales.id AND tec_products.pant_shirt_category = 2) IS NULL THEN 0 ELSE (SELECT FORMAT(SUM(tec_sale_items.quantity), 0) FROM tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id = tec_products.id WHERE tec_sale_items.sale_id = tec_sales.id AND tec_products.pant_shirt_category = 2) END AS shirt_count, CASE WHEN (SELECT FORMAT(SUM(tec_sale_items.quantity), 0) FROM tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id = tec_products.id WHERE tec_sale_items.sale_id = tec_sales.id AND tec_products.pant_shirt_category = 1) IS NULL THEN 0 ELSE (SELECT FORMAT(SUM(tec_sale_items.quantity), 0) FROM tec_sale_items LEFT JOIN tec_products ON tec_sale_items.product_id = tec_products.id WHERE tec_sale_items.sale_id = tec_sales.id AND tec_products.pant_shirt_category = 1) END AS pant_count, IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign'))) as neww_musthafa_cutting, IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=2 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=2 and tec_work_units.assign_or_not='assign'))) as neww_musthafa_stitching, (SELECT phone FROM tec_customers WHERE tec_sales.customer_id=tec_customers.id) as customer_phone, (SELECT phone FROM tec_customers WHERE tec_sales.customer_id=tec_customers.id) as customer_phone"); } $this->datatables->from('sales'); if (!$this->Admin && !$this->session->userdata('view_right')) { $this->datatables->where('created_by', $this->session->userdata('user_id')); } $this->datatables->where('store_id', $this->session->userdata('store_id')); $this->datatables->add_column('View', "<div class='text-center btn-group'> <a href='" . site_url('sales/?sale_id=$2') . "' title='View Sales' data-toggle='modal' target='a_blank' class='btn btn-warning btn-xs'> <i class='fa fa-shopping-cart'></i> </a> <a href='" . site_url('pos/view/$1') . "' title='View Measurement' data-toggle='modal' target='a_blank' class='btn btn-success btn-xs'> <i class='fa fa-eye'></i> </a> </div>", 'id, hold_ref'); $this->datatables->add_column('Actions', "<div class='text-center'><div class='btn-group'><span title='Ready All Products' id='$1' onClick='readyAllproductsClick($1,$2,$3)' class='tip btn btn-success btn-xs ready_check'><i class='fa fa-check'></i></span><span title='Send SMS' id='$1' class='tip btn btn-info btn-xs sms'><i class='fa fa-envelope-o'></i></span><span title='History' id='$1' class='tip btn btn-warning btn-xs view-history'><i class='fa fa-history'></i></span> <a href='" . site_url('pos/?clone=$1') . "' title='Clone' class='tip btn btn-success btn-xs'><i class='fa fa-copy'></i></a> <a href='" . site_url('sales/payments/$1') . "' title='" . lang('view_payments') . "' class='tip btn btn-primary btn-xs' data-toggle='ajax'><i class='fa fa-money'></i></a> <a href='" . site_url('sales/add_payment/$1') . "' title='" . lang('add_payment') . "' class='tip btn btn-primary btn-xs' data-toggle='ajax'><i class='fa fa-briefcase'></i></a> <a href='" . site_url('pos/?edit=$1') . "' title='" . lang('edit_invoice') . "' class='tip btn btn-warning btn-xs'><i class='fa fa-edit'></i></a> <a href='" . site_url('sales/delete/$1') . "' onClick=\"return confirm('" . lang('alert_x_sale') . "')\" title='" . lang('delete_sale') . "' class='tip btn btn-danger btn-xs'><i class='fa fa-trash-o'></i></a></div></div>", 'id, neww_musthafa_cutting, neww_musthafa_stitching'); $this->datatables->edit_column('sale_type_name', "<div class='text-center'><b style='color: red;' onClick='ready($1,$2,$3)'><b>$1</div>",'sale_type_name'); $this->datatables->edit_column('Ready', "$2$3",'id, neww_musthafa_cutting, neww_musthafa_stitching'); if($start_date) { $this->datatables->where('due_date >=', $start_date); } if($end_date) { $this->datatables->where('due_date <=', $end_date); } if($unit_status==1) { $where = "(IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=2 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=2 and tec_work_units.assign_or_not='assign'))) > 0 or IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign')) > 0) "; //$where = "IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign')) > 0 "; $this->datatables->where($where); // $this->datatables->where("IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=2 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=2 and tec_work_units.assign_or_not='assign'))) >", 0); // $this->datatables->where("IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign')) >", 0); } else if($unit_status==2) { $this->datatables->where("IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=2 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=2 and tec_work_units.assign_or_not='assign'))) =", '0'); $this->datatables->where("IF(((SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign')) is NULL,(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service'),(SELECT sum(tec_sale_items.quantity) FROM tec_sale_items WHERE tec_sale_items.sale_id=tec_sales.id and product_type='service')-(SELECT sum(tec_work_units.quantity) FROM tec_work_units WHERE tec_work_units.sale_id=tec_sales.id and tec_work_units.type=1 and tec_work_units.assign_or_not='assign')) =", '0'); } echo $this->datatables->generate(); } // Get Sales Endss Here public function signing($req = null) { if (!$req) { header('Content-type: text/plain'); echo file_get_contents('./files/public.pem'); exit(0); } $privateKey = openssl_get_privatekey(file_get_contents('./files/private.pem'), 'S3cur3P@ssw0rd'); $signature = null; openssl_sign($req, $signature, $privateKey); if ($signature) { header('Content-type: text/plain'); echo base64_encode($signature); exit(0); } echo '<h1>Error signing message</h1>'; exit(1); } }