PHP File Manager
Editing File: Sales.php
<?php /* * Copyright (C) Wayne Purton-Smith - All Rights Reserved * Unauthorized copying of this file or removing this paragraph, via any medium is strictly prohibited * Proprietary and confidential * Written by Wayne Purton-Smith <waynepurtonsmith@hotmail.co.uk> February 2014 */ class Sales extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('accounting'); } public function index() { $head_data['page_title'] = 'Accounting'; $this->load->view('header', $head_data); $data['account_tabs'] = $this->accounting->getTabs(); $data['total_tabs'] = $this->common->countPreviousQuery(); $this->load->view('accounting/overview', $data); $this->load->view('footer'); } public function tab($tab_id = 0) { if(($tab_id = (int) $tab_id) <= 0 || !($tab_info = $this->accounting->getTabs($tab_id))) { redirect('/accounting'); exit; } $data['tab_info'] = $tab_info; $page_number = (is_numeric($this->uri->segment(4))) ? $this->uri->segment(4) : 1; $data['tab_reports'] = $this->accounting->get(NULL, $tab_id, array('group_date' => true), $page_number); $data['total_reports'] = $this->common->countPreviousQuery(); $search_filters = array(); $viewing_year = date('Y'); $viewing_month = date('n'); $viewing_day = date('j'); if($this->uri->rsegment(4) == 'date' && $this->uri->rsegment(7)) { list($viewing_year, $viewing_month, $viewing_day) = array($this->uri->rsegment(7), $this->uri->rsegment(6), $this->uri->rsegment(5)); } $viewing_timestamp = strtotime($viewing_day . '-' . $viewing_month . '-' . $viewing_year . ' 00:00:00'); $search_filters['date'] = $viewing_timestamp; $viewing_report = $this->accounting->get(NULL, $tab_id, $search_filters); $months_of_year = array(); for($i = 1; $i <= 12; $i++) { $month_timestamp = strtotime('1-' . $i . '-' . $viewing_year); $months_of_year[date('F', $month_timestamp)] = date('t', $month_timestamp); } $viewing_is_sunday = (date('w', $viewing_timestamp) == 6); $data['current_month'] = date('n'); $data['viewing_year'] = $viewing_year; $data['viewing_month'] = $viewing_month; $data['viewing_day'] = $viewing_day; $data['viewing_timestamp'] = $viewing_timestamp; $data['previous_timestamp'] = strtotime('-1 day', $viewing_timestamp); $data['next_timestamp'] = strtotime('+1 day', $viewing_timestamp); $data['viewing_is_sunday'] = $viewing_is_sunday; $data['viewing_is_today'] = ($viewing_timestamp === strtotime('00:00:00')); $data['months_of_year'] = $months_of_year; $data['viewing_report'] = $viewing_report; $data['cash_types'] = $this->accounting->getCashTypes(); $calendar_reports = array(); array_map(function($report_info) use(&$calendar_reports) { $calendar_reports[date('j-n-Y', $report_info->date)] = array('id' => $report_info->report_id, 'end' => $report_info->has_end_result); }, $this->accounting->get(NULL, $tab_id, NULL, -1)); $data['calendar_reports'] = $calendar_reports; $head_data['page_title'] = (($data['viewing_is_today']) ? 'Today\'s' : date('D, jS F Y', $viewing_timestamp)) . ' report - ' . $tab_info->name; $this->load->view('header', $head_data); $this->load->view('accounting/tab', $data); $this->load->view('footer'); } public function accounts($mode = NULL, $tab_id = 0) { if(($mode == 'edit' || $mode == 'delete') && ($tab_id = (int) $tab_id) <= 0 || !($tab_info = $this->accounting->getTabs($tab_id))) { redirect('/accounting'); exit; } if($mode == 'delete') { $this->accounting->deleteTab($tab_id); redirect('/accounting'); exit; } if($this->input->post('save_tab')) { if(!$this->accounting->saveTab($this->input->post(), $this->input->post('tab_id'))) { $this->common->keepPostData(); } $this->common->keepResponseMessage(); redirect('/accounting/accounts/edit/' . $tab_id); exit; } $this->common->getPostData(); $head_data['page_title'] = (($mode == 'edit') ? 'Edit account - ' . $tab_info->name : 'New account') . ' - Accounting'; $this->load->view('header', $head_data); $data['tab_info'] = $tab_info; $this->load->view('accounting/edit', $data); $this->load->view('footer'); } public function file($tab_id = 0) { $editing_report = false; if($this->uri->segment(2) == 'edit' && ($report_id = (int) $this->uri->segment(3)) > 0) { if(!($report_info = $this->accounting->get($report_id))) { redirect('/accounting'); exit; } $tab_info = $this->accounting->getTabs($report_info->tab_id); $tab_id = $report_info->tab_id; $data['viewing_report'] = $report_info; $editing_report = true; } else { if(($tab_id = (int) $tab_id) <= 0 || !($tab_info = $this->accounting->getTabs($tab_id))) { redirect('/accounting'); exit; } } if($this->input->post('save_report') || $this->input->post('save_report_tomorrow')) { if(($report_id = $this->accounting->save($tab_id, $this->input->post(), $this->input->post('report_id')))) { $report_info = $this->accounting->get($report_id); $this->common->keepResponseMessage(); if($this->input->post('save_report_tomorrow')) { $report_date = strtotime('tomorrow'); } else { $report_date = $report_info->date; } redirect('/accounting/tab/' . $tab_id . '/date/' . date('d/m/Y', $report_date)); exit; } else { $this->common->keepResponseMessage(); $this->common->keepPostData(); redirect($this->agent->referrer()); exit; } } $this->common->getPostData(); $head_data['page_title'] = (($editing_report) ? 'Edit' : 'New') . ' report - ' . $tab_info->name; $this->load->view('header', $head_data); if(isset($report_info->date)) { $report_date = $report_info->date; } else { $report_date = strtotime('00:00:00'); if($this->uri->segment(4) == 'date' && $this->uri->segment(7)) { if(($_file_date = strtotime($this->uri->segment(5) . '-' . $this->uri->segment(6) . '-' . $this->uri->segment(7))) > 1) { $report_date = $_file_date; } } } $data['report_date'] = $report_date; $data['editing_report'] = $editing_report; $data['tab_info'] = $tab_info; $data['default_cash'] = $this->accounting->getDefaultCash($tab_id); $data['cash_types'] = $this->accounting->getCashTypes(); $this->load->view('accounting/file', $data); $this->load->view('footer'); } public function view($tab_mode = NULL, $sub_tab_mode = NULL) { if($tab_mode == 'tab' && ($tab_id = (int) $sub_tab_mode) > 0) { if(!($tab_info = $this->accounting->getTabs($tab_id))) { redirect('/accounting'); exit; } $search_filters = array(); if($this->uri->rsegment(5) == 'date' && $this->uri->rsegment(8)) { $search_filters['date'] = strtotime($this->uri->rsegment(6) . '-' . $this->uri->rsegment(7) . '-' . $this->uri->rsegment(8) . ' 00:00:00'); } $tab_reports = $this->accounting->get(NULL, $tab_id, $search_filters); } else { } $head_data['page_title'] = 'Accounting'; $this->load->view('header', $head_data); $data['tab_reports'] = $tab_reports; $this->load->view('accounting/view', $data); $this->load->view('footer'); } public function customers($mode = NULL, $sub_mode = NULL) { if($mode == 'view') { if(!(($customer_id = (int) $sub_mode) > 0 && ($customer_info = $this->customers->get($customer_id)))) { redirect('/accounting/customers'); exit; } $head_data['page_title'] = (($customer_info->business) ? $customer_info->business : format_display($customer_info->first_name, $customer_info->last_name)) . ' - Accounting'; $template_name = 'customer-payments'; } else { $head_data['page_title'] = 'Customers - Accounting'; $customers = $this->customers->get(NULL, array('exclude_requests' => true), $mode, $this->common->default_per_page); $total_customers = $this->common->countPreviousQuery(); $data['customers'] = $customers; $data['total_customers'] = $total_customers; $template_name = 'customers'; } $this->load->view('header', $head_data); $this->load->view('accounting/' . $template_name, $data); $this->load->view('footer'); } public function delete($report_id = 0) { $this->accounting->deleteReport($report_id); redirect($this->agent->referrer()); exit; } }
Cancel