ok
Direktori : /home2/selectio/www/mm-tailor-billing/app/controllers/ |
Current File : //home2/selectio/www/mm-tailor-billing/app/controllers/Customers.php |
<?php defined('BASEPATH') or exit('No direct script access allowed'); class Customers extends MY_Controller { public function __construct() { parent::__construct(); if (!$this->loggedIn) { redirect('login'); } $this->load->library('form_validation'); $this->load->model('customers_model'); } public function view($id = null) { $this->data['customer'] = $this->customers_model->getCustomerByID($id); /*$this->data['customers'] = $this->customers_model->getCustomerDetails($id);*/ $this->load->view($this->theme . 'customers/view_details', $this->data); } public function add() { $this->form_validation->set_rules('name', $this->lang->line('name'), 'required'); $this->form_validation->set_rules('email', $this->lang->line('email_address'), 'valid_email'); if ($this->form_validation->run() == true) { $data = ['name' => $this->input->post('name'), 'email' => $this->input->post('email'), 'phone' => $this->input->post('phone'), 'cf1' => $this->input->post('cf1'), 'cf2' => $this->input->post('cf2'), ]; } if ($this->form_validation->run() == true && $cid = $this->customers_model->addCustomer($data)) { if ($this->input->is_ajax_request()) { echo json_encode(['status' => 'success', 'msg' => $this->lang->line('customer_added'), 'id' => $cid, 'val' => $data['name']]); die(); } $this->session->set_flashdata('message', $this->lang->line('customer_added')); redirect('customers'); } else { if ($this->input->is_ajax_request()) { echo json_encode(['status' => 'failed', 'msg' => validation_errors()]); die(); } $this->data['error'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('error'); $this->data['page_title'] = lang('add_customer'); $bc = [['link' => site_url('customers'), 'page' => lang('customers')], ['link' => '#', 'page' => lang('add_customer')]]; $meta = ['page_title' => lang('add_customer'), 'bc' => $bc]; $this->page_construct('customers/add', $this->data, $meta); } } public function delete($id = null) { if (DEMO) { $this->session->set_flashdata('error', $this->lang->line('disabled_in_demo')); redirect('pos'); } if ($this->input->get('id')) { $id = $this->input->get('id', true); } if (!$this->Admin) { $this->session->set_flashdata('error', lang('access_denied')); redirect('pos'); } if ($this->customers_model->deleteCustomer($id)) { $this->session->set_flashdata('message', lang('customer_deleted')); redirect('customers'); } } public function edit($id = null) { if (!$this->Admin) { $this->session->set_flashdata('error', $this->lang->line('access_denied')); redirect('pos'); } if ($this->input->get('id')) { $id = $this->input->get('id', true); } $this->form_validation->set_rules('name', $this->lang->line('name'), 'required'); $this->form_validation->set_rules('email', $this->lang->line('email_address'), 'valid_email'); if ($this->form_validation->run() == true) { $data = ['name' => $this->input->post('name'), 'email' => $this->input->post('email'), 'phone' => $this->input->post('phone'), 'cf1' => $this->input->post('cf1'), 'cf2' => $this->input->post('cf2'), ]; } if ($this->form_validation->run() == true && $this->customers_model->updateCustomer($id, $data)) { $this->session->set_flashdata('message', $this->lang->line('customer_updated')); redirect('customers'); } else { $this->data['customer'] = $this->customers_model->getCustomerByID($id); $this->data['error'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('error'); $this->data['page_title'] = lang('edit_customer'); $bc = [['link' => site_url('customers'), 'page' => lang('customers')], ['link' => '#', 'page' => lang('edit_customer')]]; $meta = ['page_title' => lang('edit_customer'), 'bc' => $bc]; $this->page_construct('customers/edit', $this->data, $meta); } } /*(SELECT CONCAT(IFNULL(dc_prefix, ''), hold_ref) FROM tec_sales WHERE tec_sales.customer_id = tec_customers.id ORDER BY tec_sales.id DESC LIMIT 1) as last_dc_number*/ /*$this->datatables ->select('customers.id, name, phone, email, cf1, cf2, (SELECT COUNT(id) from tec_sales where tec_sales.customer_id=tec_customers.id) as dc_count,(SELECT (SUM(tec_sales.grand_total) - (SUM(tec_sales.paid)+SUM(tec_sales.discount))) from tec_sales where tec_sales.customer_id=tec_customers.id) AS customer_balance, (SELECT MAX(hold_ref) from tec_sales where tec_sales.customer_id=tec_customers.id) as last_dc_number') ->from('customers');*/ /*(SELECT MAX(CONCAT(IFNULL(dc_prefix, ''), hold_ref)) FROM tec_sales WHERE tec_sales.customer_id = tec_customers.id) as dc_last_number*/ public function get_customers() { $this->load->library('datatables'); $this->datatables ->select('customers.id, name, phone, email, cf1, cf2, (SELECT COUNT(id) from tec_sales where tec_sales.customer_id=tec_customers.id) as dc_count,(SELECT (SUM(tec_sales.grand_total) - (SUM(tec_sales.paid)+SUM(tec_sales.discount))) from tec_sales where tec_sales.customer_id=tec_customers.id) AS customer_balance, (SELECT CONCAT(IFNULL(dc_prefix, ""), hold_ref) from tec_sales where tec_sales.customer_id=tec_customers.id ORDER BY tec_sales.id DESC LIMIT 1) as last_dc_number') ->from('customers'); //$this->datatables->join('sales', 'customers.id = sales.customer_id'); $this->datatables->add_column('Actions', "<div class='text-center'><div class='btn-group'><a href='" . site_url('customers/view/$1') . "' data-toggle='ajax' class='tip btn btn-info btn-xs' title='View Customer'><i class='fa fa-eye'></i></a><a href='" . site_url('customers/edit/$1') . "' class='tip btn btn-warning btn-xs' title='" . $this->lang->line('edit_customer') . "'><i class='fa fa-edit'></i></a> <a href='" . site_url('customers/delete/$1') . "' onClick=\"return confirm('" . $this->lang->line('alert_x_customer') . "')\" class='tip btn btn-danger btn-xs' title='" . $this->lang->line('delete_customer') . "'><i class='fa fa-trash-o'></i></a></div></div>", 'id') ->unset_column('id'); /*<span href='' class='tip btn btn-info btn-xs clone' title='Customers History' id='$1'><i class='fa fa-check-circle-o'> Customers Sales History</i></span>*/ $this->datatables->add_column('DC', "<div class='text-center'><span class='btn btn-warning btn-xs' style='font-size: 20px; font-weight: 900; padding: 0px 15px 0px 15px;'> $2 </span></div>", 'id, last_dc_number, dc_count'); $this->datatables->add_column('Clone', "<div class='text-center'><div class='btn-group'><a href='" . site_url('sales/?cus=$1') . "' class='btn btn-primary btn-xs'><i class='fa fa-check-circle-o'></i> Sales History</a></div></div>", 'id,dc_count,last_dc_number'); $this->datatables->add_column('DC Count', "<div class='text-center'><span href='' class='tip btn btn-success btn-xs' style='font-size: 20px; padding: 0px 8px 0px 8px;' title='DC Count'><b>$2</b></span></div>", 'id,dc_count'); //$this->datatables->add_column('DC Count', "<div class='text-center'><div class='btn-group'><span href='' class='tip btn btn-success btn-xs' title='DC Count'>DC Count : <b>$2</b></i></span></div></div>", 'id,dc_count'); //$this->datatables->add_column('Balance', "<div class='text-center'><div class='btn-group'><span href='' class='tip btn btn-danger btn-xs clone' style='font-family: arial;' title='Customers Balance' id='$1'><i class='fa fa-inr'> Balance: $2 </i></span></div></div>", 'id,customer_balance'); echo $this->datatables->generate(); } // Sales Clone - Sales ID Starts Here public function get_all_sale_items() { $customers_id = $this->input->get('customer_id'); $data = $this->customers_model->getSalesByCustomerID($customers_id); $content=''; if($data){ $content='<table style="width: 100%;border: 1px solid black;"> <tr> <th class="history_table">DC Number</th> <th class="history_table">Pant Count</th> <th class="history_table">Shirt Count</th> <th class="history_table">DC Status</th> <th class="history_table">Balance</th> <th class="history_table">Clone</th> <th class="history_table">Date</th> </tr>'; foreach($data as $d){ if($d->unit_process_status==1){$status="<div class='text-center'><span class='upsale_status label label-info'>Measurement Collected</span></div>";} if($d->unit_process_status==2){$status="<div class='text-center'><span class='upsale_status label label-danger'>Cutting Unit (Partial Assigned)</span></div>";} if($d->unit_process_status==3){$status="<div class='text-center'><span class='upsale_status label label-warning'>Cutting Unit (Fully Assigned)</span></div>";} if($d->unit_process_status==4){$status="<div class='text-center'><span class='upsale_status label label-danger'>Stitching Unit (Partial Assigned)</span></div>";} if($d->unit_process_status==5){$status="<div class='text-center'><span class='upsale_status label label-warning'>Stitching Unit (Fully Assigned)</span></div>";} if($d->unit_process_status==6){$status="<div class='text-center'><span class='upsale_status label label-warning'>Ready to Delivery (Partial)</span></div>";} if($d->unit_process_status==7){$status="<div class='text-center'><span class='upsale_status label label-primary'>Ready to Delivery</span></div>";} if($d->unit_process_status==8){$status="<div class='text-center'><span class='upsale_status label label-warning'>Order Delivered (Partial)</span></div>";} if($d->unit_process_status==9){$status="<div class='text-center'><span class='upsale_status label label-success'>Order Delivered</span></div>";} $balance=($d->grand_total)-($d->paid); $date = date("Y-m-d", $d->date); $content.='<tr>'; $content.='<td class="history_table">'.$d->hold_ref.'</td>'; $content.='<td class="history_table">'.$d->shirt_count.'</td>'; $content.='<td class="history_table">'.$d->pant_count.'</td>'; $content.='<td class="history_table">'.$status.'</td>'; if($balance==0) { $content.='<td class="history_table"> <a class="">NULL</a> </td>'; } else { $content.='<td class="history_table"> <a class="btn btn-danger btn-xs">'.number_format($balance,2).'</a> </td>'; } $content.='<td class="history_table"><a class="btn btn-warning btn-xs" href="pos/?clone='.$d->id.'">CLONE</a></td>'; $content.='<td class="history_table">'.date("d-m-Y", strtotime($d->sale_date)).'</td>'; $content.='</tr>'; $content.='<style> .history_table { border: 1px solid #dddddd; text-align: center; padding: 7px; } </style>'; } $content.='</table>'; }else{ $content.='<center><b>No Data Available</b></center>'; } echo $content; } // Sales Clone - Sales ID Ends Here public function index() { $this->data['error'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('error'); $this->data['page_title'] = lang('customers'); $bc = [['link' => '#', 'page' => lang('customers')]]; $meta = ['page_title' => lang('customers'), 'bc' => $bc]; $this->page_construct('customers/index', $this->data, $meta); } /*public function reports() { $this->data['error'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('error'); $this->data['page_title'] = lang('customers_report'); $bc = [['link' => '#', 'page' => lang('customers_report')]]; $meta = ['page_title' => lang('customers_report'), 'bc' => $bc]; $this->page_construct('customers/reports', $this->data, $meta); }*/ }