Add cashup feature

This commit is contained in:
FrancescoUK
2018-07-14 09:39:52 +01:00
parent 4420dccc60
commit b3bfc51ee8
15 changed files with 1034 additions and 5 deletions

View File

@@ -132,4 +132,4 @@ $autoload['language'] = array();
|
| $autoload['model'] = array('first_model' => 'first');
*/
$autoload['model'] = array('Appconfig', 'Person', 'Customer', 'Employee', 'Module', 'Item', 'Item_taxes', 'Sale', 'Supplier', 'Inventory', 'Receiving', 'Giftcard', 'Item_kit', 'Item_kit_items', 'Stock_location', 'Item_quantity', 'Dinner_table', 'Customer_rewards', 'Rewards', 'Tax', 'Expense_category', 'Expense' );
$autoload['model'] = array('Appconfig', 'Person', 'Customer', 'Employee', 'Module', 'Item', 'Item_taxes', 'Sale', 'Supplier', 'Inventory', 'Receiving', 'Giftcard', 'Item_kit', 'Item_kit_items', 'Stock_location', 'Item_quantity', 'Dinner_table', 'Customer_rewards', 'Rewards', 'Tax', 'Expense_category', 'Expense', 'Cashup');

View File

@@ -0,0 +1,240 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once("Secure_Controller.php");
class Cashups extends Secure_Controller
{
public function __construct()
{
parent::__construct('cashups');
}
public function index()
{
$data['table_headers'] = $this->xss_clean(get_cashups_manage_table_headers());
// filters that will be loaded in the multiselect dropdown
$data['filters'] = array('is_deleted' => $this->lang->line('cashups_is_deleted'));
$this->load->view('cashups/manage', $data);
}
public function search()
{
$cash_up = 0;
$search = $this->input->get('search');
$limit = $this->input->get('limit');
$offset = $this->input->get('offset');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
$filters = array(
'start_date' => $this->input->get('start_date'),
'end_date' => $this->input->get('end_date'),
'is_deleted' => FALSE);
// check if any filter is set in the multiselect dropdown
$filledup = array_fill_keys($this->input->get('filters'), TRUE);
$filters = array_merge($filters, $filledup);
$cash_ups = $this->Cashup->search($search, $filters, $limit, $offset, $sort, $order);
$total_rows = $this->Cashup->get_found_rows($search, $filters);
$data_rows = array();
foreach($cash_ups->result() as $cash_up)
{
$data_rows[] = $this->xss_clean(get_cash_up_data_row($cash_up));
}
echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
}
public function view($cashup_id = -1)
{
$data = array();
$data['employees'] = array();
foreach($this->Employee->get_all()->result() as $employee)
{
foreach(get_object_vars($employee) as $property => $value)
{
$employee->$property = $this->xss_clean($value);
}
$data['employees'][$employee->person_id] = $employee->first_name . ' ' . $employee->last_name;
}
$cash_ups_info = $this->Cashup->get_info($cashup_id);
foreach(get_object_vars($cash_ups_info) as $property => $value)
{
$cash_ups_info->$property = $this->xss_clean($value);
}
// open cashup
if(empty($cash_ups_info->cashup_id))
{
$cash_ups_info->open_date = date('Y-m-d H:i:s');
$cash_ups_info->close_date = $cash_ups_info->open_date;
$cash_ups_info->open_employee_id = $this->Employee->get_logged_in_employee_info()->person_id;
$cash_ups_info->close_employee_id = $this->Employee->get_logged_in_employee_info()->person_id;
}
// if all the amounts are null or 0 that means it's a close cashup
elseif(floatval($cash_ups_info->closed_amount_cash) == 0 &&
floatval($cash_ups_info->closed_amount_card) == 0 &&
floatval($cash_ups_info->closed_amount_check) == 0)
{
// set the close date and time to the actual as this is a close session
$cash_ups_info->close_date = date('Y-m-d H:i:s');
// the closed amount starts with the open amount -/+ any trasferred amount
$cash_ups_info->closed_amount_cash = $cash_ups_info->open_amount_cash + $cash_ups_info->transfer_amount_cash;
// if it's date mode only and not date & time truncate the open and end date to date only
if(empty($this->config->item('date_or_time_format')))
{
// search for all the payments given the time range
$inputs = array('start_date' => substr($cash_ups_info->open_date, 0, 10), 'end_date' => substr($cash_ups_info->close_date, 0, 10), 'sale_type' => 'complete', 'location_id' => 'all');
}
else
{
// search for all the payments given the time range
$inputs = array('start_date' => $cash_ups_info->open_date, 'end_date' => $cash_ups_info->close_date, 'sale_type' => 'complete', 'location_id' => 'all');
}
// get all the transactions payment summaries
$this->load->model('reports/Summary_payments');
$reports_data = $this->Summary_payments->getData($inputs);
foreach($reports_data as $row)
{
if($row['payment_type'] == $this->lang->line('sales_cash'))
{
$cash_ups_info->closed_amount_cash += $this->xss_clean($row['payment_amount']);
}
elseif($row['payment_type'] == $this->lang->line('sales_due'))
{
$cash_ups_info->closed_amount_cash -= $this->xss_clean($row['payment_amount']);
}
elseif($row['payment_type'] == $this->lang->line('sales_debit') ||
$row['payment_type'] == $this->lang->line('sales_credit'))
{
$cash_ups_info->closed_amount_card += $this->xss_clean($row['payment_amount']);
}
elseif($row['payment_type'] == $this->lang->line('sales_check'))
{
$cash_ups_info->closed_amount_check += $this->xss_clean($row['payment_amount']);
}
}
// lookup expenses paid in cash
$filters = array(
'only_cash' => TRUE,
'only_due' => FALSE,
'only_check' => FALSE,
'only_credit' => FALSE,
'only_debit' => FALSE,
'is_deleted' => FALSE);
$payments = $this->Expense->get_payments_summary('', array_merge($inputs, $filters));
foreach($payments as $row)
{
$cash_ups_info->closed_amount_cash -= $this->xss_clean($row['amount']);
}
$cash_ups_info->closed_amount_total = $this->_calculate_total($cash_ups_info->open_amount_cash, $cash_ups_info->transfer_amount_cash, $cash_ups_info->closed_amount_cash, $cash_ups_info->closed_amount_card, $cash_ups_info->closed_amount_check);
}
$data['cash_ups_info'] = $cash_ups_info;
$this->load->view("cashups/form", $data);
}
public function get_row($row_id)
{
$cash_ups_info = $this->Cashup->get_info($row_id);
$data_row = $this->xss_clean(get_cash_up_data_row($cash_ups_info));
echo json_encode($data_row);
}
public function save($cashup_id = -1)
{
$open_date = $this->input->post('open_date');
$open_date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $open_date);
$close_date = $this->input->post('close_date');
$close_date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $close_date);
$cash_up_data = array(
'open_date' => $open_date_formatter->format('Y-m-d H:i:s'),
'close_date' => $close_date_formatter->format('Y-m-d H:i:s'),
'open_amount_cash' => parse_decimals($this->input->post('open_amount_cash')),
'transfer_amount_cash' => parse_decimals($this->input->post('transfer_amount_cash')),
'closed_amount_cash' => parse_decimals($this->input->post('closed_amount_cash')),
'closed_amount_card' => parse_decimals($this->input->post('closed_amount_card')),
'closed_amount_check' => parse_decimals($this->input->post('closed_amount_check')),
'closed_amount_total' => parse_decimals($this->input->post('closed_amount_total')),
'note' => $this->input->post('note') != NULL,
'description' => $this->input->post('description'),
'open_employee_id' => $this->input->post('open_employee_id'),
'close_employee_id' => $this->input->post('close_employee_id'),
'deleted' => $this->input->post('deleted') != NULL
);
if($this->Cashup->save($cash_up_data, $cashup_id))
{
$cash_up_data = $this->xss_clean($cash_up_data);
//New cashup_id
if($cashup_id == -1)
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('cashups_successful_adding'), 'id' => $cash_up_data['cashup_id']));
}
else // Existing Cashup
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('cashups_successful_updating'), 'id' => $cashup_id));
}
}
else//failure
{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('cashups_error_adding_updating'), 'id' => -1));
}
}
public function delete()
{
$cash_ups_to_delete = $this->input->post('ids');
if($this->Cashup->delete_list($cash_ups_to_delete))
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('cashups_successful_deleted') . ' ' . count($cash_ups_to_delete) . ' ' . $this->lang->line('cashups_one_or_multiple'), 'ids' => $cash_ups_to_delete));
}
else
{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('cashups_cannot_be_deleted'), 'ids' => $cash_ups_to_delete));
}
}
/*
AJAX call from cashup input form to calculate the total
*/
public function ajax_cashup_total()
{
$open_amount_cash = parse_decimals($this->input->post('open_amount_cash'));
$transfer_amount_cash = parse_decimals($this->input->post('transfer_amount_cash'));
$closed_amount_cash = parse_decimals($this->input->post('closed_amount_cash'));
$closed_amount_card = parse_decimals($this->input->post('closed_amount_card'));
$closed_amount_check = parse_decimals($this->input->post('closed_amount_check'));
$total = $this->_calculate_total($open_amount_cash, $transfer_amount_cash, $closed_amount_cash, $closed_amount_card, $closed_amount_check);
echo json_encode(array('total' => to_currency_no_money($total)));
}
/*
Calculate total
*/
private function _calculate_total($open_amount_cash, $transfer_amount_cash, $closed_amount_cash, $closed_amount_card, $closed_amount_check)
{
return ($closed_amount_cash - $open_amount_cash - $transfer_amount_cash + $closed_amount_card + $closed_amount_check);
}
}
?>

View File

@@ -579,7 +579,7 @@ function get_expenses_manage_table_headers()
}
/*
Gets the html data row for the expenses.
Gets the html data row for the expenses
*/
function get_expenses_data_row($expense)
{
@@ -643,4 +643,53 @@ function get_expenses_manage_payments_summary($payments, $expenses)
return $table;
}
/*
Get the header for the cashup tabular view
*/
function get_cashups_manage_table_headers()
{
$CI =& get_instance();
$headers = array(
array('cashup_id' => $CI->lang->line('cashups_id')),
array('open_date' => $CI->lang->line('cashups_opened_date')),
array('open_employee_id' => $CI->lang->line('cashups_open_employee')),
array('open_amount_cash' => $CI->lang->line('cashups_open_amount_cash')),
array('transfer_amount_cash' => $CI->lang->line('cashups_transfer_amount_cash')),
array('close_date' => $CI->lang->line('cashups_closed_date')),
array('close_employee_id' => $CI->lang->line('cashups_close_employee')),
array('closed_amount_cash' => $CI->lang->line('cashups_closed_amount_cash')),
array('note' => $CI->lang->line('cashups_note')),
array('closed_amount_card' => $CI->lang->line('cashups_closed_amount_card')),
array('closed_amount_check' => $CI->lang->line('cashups_closed_amount_check')),
array('closed_amount_total' => $CI->lang->line('cashups_closed_amount_total'))
);
return transform_headers($headers);
}
/*
Gets the html data row for the cashups
*/
function get_cash_up_data_row($cash_up)
{
$CI =& get_instance();
$controller_name = strtolower(get_class($CI));
return array (
'cashup_id' => $cash_up->cashup_id,
'open_date' => date($CI->config->item('dateformat') . ' ' . $CI->config->item('timeformat'), strtotime($cash_up->open_date)),
'open_employee_id' => $cash_up->open_first_name . ' ' . $cash_up->open_last_name,
'open_amount_cash' => to_currency($cash_up->open_amount_cash),
'transfer_amount_cash' => to_currency($cash_up->transfer_amount_cash),
'close_date' => date($CI->config->item('dateformat') . ' ' . $CI->config->item('timeformat'), strtotime($cash_up->close_date)),
'close_employee_id' => $cash_up->close_first_name . ' ' . $cash_up->close_last_name,
'closed_amount_cash' => to_currency($cash_up->closed_amount_cash),
'note' => $cash_up->note ? '<span class="glyphicon glyphicon-ok"></span>' : '<span class="glyphicon glyphicon-remove"></span>',
'closed_amount_card' => to_currency($cash_up->closed_amount_card),
'closed_amount_check' => to_currency($cash_up->closed_amount_check),
'closed_amount_total' => to_currency($cash_up->closed_amount_total),
'edit' => anchor($controller_name."/view/$cash_up->cashup_id", '<span class="glyphicon glyphicon-edit"></span>',
array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update'))
));
}
?>

View File

@@ -0,0 +1,38 @@
<?php
$lang["cashups_close_date"] = "Close Date";
$lang["cashups_confirm_delete"] = "Are you sure you want to delete the selected Cashup?";
$lang["cashups_confirm_restore"] = "Are you sure you want to restore selected Cashup(s)?";
$lang["cashups_date_required"] = "Date is a required field";
$lang["cashups_description"] = "Description";
$lang["cashups_error_adding_updating"] = "Error adding/updating Cashup";
$lang["cashups_info"] = "Cashups Info";
$lang["cashups_id"] = "Id";
$lang["cashups_open_employee"] = "Opened By";
$lang["cashups_close_employee"] = "Closed By";
$lang["cashups_open_date"] = "Open Date";
$lang["cashups_opened_date"] = "Opened Date";
$lang["cashups_closed_date"] = "Closed Date";
$lang["cashups_amount"] = "Amount";
$lang["cashups_amount_required"] = "Amount is a Required Field";
$lang['cashups_closed_amount_total'] = "Total";
$lang['cashups_open_amount_cash'] = "Open Cash";
$lang['cashups_transfer_amount_cash'] = "In/Out Cash";
$lang['cashups_closed_amount_cash'] = "Closed Cash";
$lang['cashups_closed_amount_card'] = "Cards";
$lang['cashups_closed_amount_check'] = "Cheques";
$lang["cashups_new"] = "New Cashup";
$lang["cashups_no_cashups_to_display"] = "There are no Cashups to display";
$lang["cashups_none_selected"] = "You have not selected any Cashups";
$lang['cashups_note'] = "Notes";
$lang["cashups_one_or_multiple"] = "Cashups(s)";
$lang["cashups_successful_adding"] = "Cashup add successful";
$lang["cashups_successful_deleted"] = "Cashup delete successful";
$lang["cashups_successful_updating"] = "Cashup update successful";
$lang["cashups_update"] = "Update Cashup";
$lang["cashups_total"] = "Total";
$lang["cashups_amount_number"] = "Amount must be a number";
$lang["cashups_amount_required"] = "Amount is a required field";
$lang["cashups_date_number"] = "Date must be a number";
$lang["cashups_date_required"] = "Date is a required field";
$lang["cashups_is_deleted"] = "Deleted";
$lang["cashups_cannot_be_deleted"] = "Cashup cannot be deleted";

View File

@@ -5,6 +5,7 @@ $lang["expenses_categories_add_item"] = "Add Category";
$lang["expenses_categories_cannot_be_deleted"] = "Could not delete Category Expense(s)";
$lang["expenses_categories_category_id"] = "Id";
$lang["expenses_categories_confirm_delete"] = "Are you sure you want to delete the selected Expense Category?";
$lang["expenses_categories_confirm_restore"] = "Are you sure you want to restore the selected Expense Category?";
$lang["expenses_categories_description"] = "Category Description";
$lang["expenses_categories_error_adding_updating"] = "Error adding/updating Expense Category";
$lang["expenses_categories_info"] = "Category Expense Info";

View File

@@ -3,6 +3,8 @@
$lang["module_both"] = "Both";
$lang["module_config"] = "Configuration";
$lang["module_config_desc"] = "Change OSPOS's Configuration";
$lang["module_cashups"] = "Cashups";
$lang["module_cashups_desc"] = "Add, Update, Delete, and Search Cashups";
$lang["module_customers"] = "Customers";
$lang["module_customers_desc"] = "Add, Update, Delete, and Search Customers";
$lang["module_employees"] = "Employees";

View File

@@ -11,9 +11,9 @@ $lang["sales_cash"] = "Cash";
$lang["sales_cash_deposit"] = "Cash Deposit";
$lang["sales_cash_filter"] = "Cash";
$lang["sales_change_due"] = "Change Due";
$lang["sales_check"] = "Check";
$lang["sales_check_balance"] = "Check remainder";
$lang["sales_check_filter"] = "Check";
$lang["sales_check"] = "Cheque";
$lang["sales_check_balance"] = "Cheque remainder";
$lang["sales_check_filter"] = "Cheque";
$lang["sales_comment"] = "Comment";
$lang["sales_comments"] = "Comments";
$lang["sales_complete_sale"] = "Complete";

View File

@@ -0,0 +1,38 @@
<?php
$lang["cashups_close_date"] = "Close Date";
$lang["cashups_confirm_delete"] = "Are you sure you want to delete the selected Cashup?";
$lang["cashups_confirm_restore"] = "Are you sure you want to restore selected Cashup(s)?";
$lang["cashups_date_required"] = "Date is a required field";
$lang["cashups_description"] = "Description";
$lang["cashups_error_adding_updating"] = "Error adding/updating Cashup";
$lang["cashups_info"] = "Cashups Info";
$lang["cashups_id"] = "Id";
$lang["cashups_open_employee"] = "Opened By";
$lang["cashups_close_employee"] = "Closed By";
$lang["cashups_open_date"] = "Open Date";
$lang["cashups_opened_date"] = "Opened Date";
$lang["cashups_closed_date"] = "Closed Date";
$lang["cashups_amount"] = "Amount";
$lang["cashups_amount_required"] = "Amount is a Required Field.";
$lang['cashups_closed_amount_total'] = "Total";
$lang['cashups_open_amount_cash'] = "Open Cash";
$lang['cashups_transfer_amount_cash'] = "In/Out Cash";
$lang['cashups_closed_amount_cash'] = "Closed Cash";
$lang['cashups_closed_amount_card'] = "Cards";
$lang['cashups_closed_amount_check'] = "Checks";
$lang["cashups_new"] = "New Cashup";
$lang["cashups_no_cashups_to_display"] = "There are no Cashups to display";
$lang["cashups_none_selected"] = "You have not selected any Cashups";
$lang['cashups_note'] = "Notes";
$lang["cashups_one_or_multiple"] = "Cashups(s)";
$lang["cashups_successful_adding"] = "Cashup add successful";
$lang["cashups_successful_deleted"] = "Cashup delete successful";
$lang["cashups_successful_updating"] = "Cashup update successful";
$lang["cashups_update"] = "Update Cashup";
$lang["cashups_total"] = "Total";
$lang["cashups_amount_number"] = "Amount must be a number";
$lang["cashups_amount_required"] = "Amount is a required field";
$lang["cashups_date_number"] = "Date must be a number";
$lang["cashups_date_required"] = "Date is a required field";
$lang["cashups_is_deleted"] = "Deleted";
$lang["cashups_cannot_be_deleted"] = "Cashup cannot be deleted";

View File

@@ -5,6 +5,7 @@ $lang["expenses_categories_add_item"] = "Add Category";
$lang["expenses_categories_cannot_be_deleted"] = "Could not delete Category Expense(s)";
$lang["expenses_categories_category_id"] = "Id";
$lang["expenses_categories_confirm_delete"] = "Are you sure you want to delete the selected Expense Category?";
$lang["expenses_categories_confirm_restore"] = "Are you sure you want to restore the selected Expense Category?";
$lang["expenses_categories_description"] = "Category Description";
$lang["expenses_categories_error_adding_updating"] = "Error adding/updating Expense Category";
$lang["expenses_categories_info"] = "Category Expense Info";

View File

@@ -3,6 +3,8 @@
$lang["module_both"] = "Both";
$lang["module_config"] = "Configuration";
$lang["module_config_desc"] = "Change OSPOS's Configuration.";
$lang["module_cashups"] = "Cashups";
$lang["module_cashups_desc"] = "Add, Update, Delete, and Search Cashups.";
$lang["module_customers"] = "Customers";
$lang["module_customers_desc"] = "Add, Update, Delete, and Search Customers.";
$lang["module_employees"] = "Employees";

View File

@@ -36,3 +36,48 @@ ALTER TABLE `ospos_sales_items`
ALTER TABLE `ospos_receivings_items`
CHANGE COLUMN `discount_percent` `discount` DECIMAL(15,2) NOT NULL DEFAULT 0 AFTER `item_unit_price`,
ADD COLUMN `discount_type` TINYINT(2) NOT NULL DEFAULT '0' AFTER `discount`;
--
-- Add support for module cashups
--
INSERT INTO `ospos_modules` (`name_lang_key`, `desc_lang_key`, `sort`, `module_id`) VALUES
('module_cashups', 'module_cashups_desc', 107, 'cashups');
INSERT INTO `ospos_permissions` (`permission_id`, `module_id`) VALUES
('cashups', 'cashups');
INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES
('cashups', 1);
-- Table structure for table `ospos_cash_up`
CREATE TABLE `ospos_cash_up` (
`cashup_id` int(10) NOT NULL,
`open_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`close_date` timestamp NULL,
`open_amount_cash` decimal(15,2) NOT NULL,
`transfer_amount_cash` decimal(15,2) NOT NULL,
`note` int(1) NOT NULL,
`closed_amount_cash` decimal(15,2) NOT NULL,
`closed_amount_card` decimal(15,2) NOT NULL,
`closed_amount_check` decimal(15,2) NOT NULL,
`closed_amount_total` decimal(15,2) NOT NULL,
`description` varchar(255) NOT NULL,
`open_employee_id` int(10) NOT NULL,
`close_employee_id` int(10) NOT NULL,
`deleted` int(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- Indexes for table `ospos_cash_up`
ALTER TABLE `ospos_cash_up`
ADD PRIMARY KEY (`cashup_id`),
ADD KEY `open_employee_id` (`open_employee_id`),
ADD KEY `close_employee_id` (`close_employee_id`);
-- AUTO_INCREMENT for table `ospos_cash_up`
ALTER TABLE `ospos_cash_up`
MODIFY `cashup_id` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;

View File

@@ -0,0 +1,210 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Cashup class
*/
class Cashup extends CI_Model
{
/*
Determines if a given Cashup_id is an Cashup
*/
public function exists($cashup_id)
{
$this->db->from('cash_up');
$this->db->where('cashup_id', $cashup_id);
return ($this->db->get()->num_rows() == 1);
}
/*
Gets employee info
*/
public function get_employee($cashup_id)
{
$this->db->from('cash_up');
$this->db->where('cashup_id', $cashup_id);
return $this->Employee->get_info($this->db->get()->row()->employee_id);
}
public function get_multiple_info($cash_up_ids)
{
$this->db->from('cash_up');
$this->db->where_in('cashup_id', $cashup_ids);
$this->db->order_by('cashup_id', 'asc');
return $this->db->get();
}
/*
Gets rows
*/
public function get_found_rows($search, $filters)
{
return $this->search($search, $filters, 0, 0, 'cashup_id', 'asc', TRUE);
}
/*
Searches cashups
*/
public function search($search, $filters, $rows = 0, $limit_from = 0, $sort = 'cashup_id', $order = 'asc', $count_only = FALSE)
{
// get_found_rows case
if($count_only == TRUE)
{
$this->db->select('COUNT(cash_up.cashup_id) as count');
}
$this->db->select('
cash_up.cashup_id,
MAX(cash_up.open_date) AS open_date,
MAX(cash_up.close_date) AS close_date,
MAX(cash_up.open_amount_cash) AS open_amount_cash,
MAX(cash_up.transfer_amount_cash) AS transfer_amount_cash,
MAX(cash_up.closed_amount_cash) AS closed_amount_cash,
MAX(cash_up.closed_amount_card) AS closed_amount_card,
MAX(cash_up.closed_amount_check) AS closed_amount_check,
MAX(cash_up.closed_amount_total) AS closed_amount_total,
MAX(cash_up.description) AS description,
MAX(cash_up.note) AS note,
MAX(cash_up.open_employee_id) AS open_employee_id,
MAX(cash_up.close_employee_id) AS close_employee_id,
MAX(open_employees.first_name) AS open_first_name,
MAX(open_employees.last_name) AS open_last_name,
MAX(close_employees.first_name) AS close_first_name,
MAX(close_employees.last_name) AS close_last_name
');
$this->db->from('cash_up AS cash_up');
$this->db->join('people AS open_employees', 'open_employees.person_id = cash_up.open_employee_id', 'LEFT');
$this->db->join('people AS close_employees', 'close_employees.person_id = cash_up.close_employee_id', 'LEFT');
$this->db->group_start();
$this->db->like('cash_up.open_date', $search);
$this->db->or_like('open_employees.first_name', $search);
$this->db->or_like('open_employees.last_name', $search);
$this->db->or_like('close_employees.first_name', $search);
$this->db->or_like('close_employees.last_name', $search);
$this->db->or_like('cash_up.closed_amount_total', $search);
$this->db->or_like('CONCAT(open_employees.first_name, " ", open_employees.last_name)', $search);
$this->db->or_like('CONCAT(close_employees.first_name, " ", close_employees.last_name)', $search);
$this->db->group_end();
$this->db->where('cash_up.deleted', $filters['is_deleted']);
if(empty($this->config->item('date_or_time_format')))
{
$this->db->where('DATE_FORMAT(cash_up.open_date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']));
}
else
{
$this->db->where('cash_up.open_date BETWEEN ' . $this->db->escape(rawurldecode($filters['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($filters['end_date'])));
}
$this->db->group_by('cashup_id');
// get_found_rows case
if($count_only == TRUE)
{
return $this->db->get()->row_array()['count'];
}
$this->db->order_by($sort, $order);
if($rows > 0)
{
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}
/*
Gets information about a particular cashup
*/
public function get_info($cashup_id)
{
$this->db->select('
cash_up.cashup_id AS cashup_id,
cash_up.open_date AS open_date,
cash_up.close_date AS close_date,
cash_up.open_amount_cash AS open_amount_cash,
cash_up.transfer_amount_cash AS transfer_amount_cash,
cash_up.closed_amount_cash AS closed_amount_cash,
cash_up.closed_amount_card AS closed_amount_card,
cash_up.closed_amount_check AS closed_amount_check,
cash_up.closed_amount_total AS closed_amount_total,
cash_up.description AS description,
cash_up.note AS note,
cash_up.open_employee_id AS open_employee_id,
cash_up.close_employee_id AS close_employee_id,
cash_up.deleted AS deleted,
open_employees.first_name AS open_first_name,
open_employees.last_name AS open_last_name,
close_employees.first_name AS close_first_name,
close_employees.last_name AS close_last_name
');
$this->db->from('cash_up AS cash_up');
$this->db->join('people AS open_employees', 'open_employees.person_id = cash_up.open_employee_id', 'LEFT');
$this->db->join('people AS close_employees', 'close_employees.person_id = cash_up.close_employee_id', 'LEFT');
$this->db->where('cashup_id', $cashup_id);
$query = $this->db->get();
if($query->num_rows() == 1)
{
return $query->row();
}
else
{
//Get empty base parent object
$cash_up_obj = new stdClass();
//Get all the fields from cashup table
foreach($this->db->list_fields('cash_up') as $field)
{
$cash_up_obj->$field = '';
}
return $cash_up_obj;
}
}
/*
Inserts or updates an cashup
*/
public function save(&$cash_up_data, $cashup_id = FALSE)
{
if(!$cashup_id == -1 || !$this->exists($cashup_id))
{
if($this->db->insert('cash_up', $cash_up_data))
{
$cash_up_data['cashup_id'] = $this->db->insert_id();
return TRUE;
}
return FALSE;
}
$this->db->where('cashup_id', $cashup_id);
return $this->db->update('cash_up', $cash_up_data);
}
/*
Deletes a list of cashups
*/
public function delete_list($cashup_ids)
{
$success = FALSE;
//Run these queries as a transaction, we want to make sure we do all or nothing
$this->db->trans_start();
$this->db->where_in('cashup_id', $cashup_ids);
$success = $this->db->update('cash_up', array('deleted'=>1));
$this->db->trans_complete();
return $success;
}
}
?>

View File

@@ -0,0 +1,340 @@
<div id="required_fields_message"><?php echo $this->lang->line('common_fields_required_message'); ?></div>
<ul id="error_message_box" class="error_message_box"></ul>
<?php echo form_open('cashups/save/'.$cash_ups_info->cashup_id, array('id'=>'cashups_edit_form', 'class'=>'form-horizontal')); ?>
<fieldset id="item_basic_info">
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_info'), 'cash_ups_info', array('class'=>'control-label col-xs-3')); ?>
<?php echo form_label(!empty($cash_ups_info->cashup_id) ? $this->lang->line('cashups_id') . ' ' . $cash_ups_info->cashup_id : '', 'cashup_id', array('class'=>'control-label col-xs-8', 'style'=>'text-align:left')); ?>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_open_date'), 'open_date', array('class'=>'required control-label col-xs-3')); ?>
<div class='col-xs-6'>
<div class="input-group">
<span class="input-group-addon input-sm"><span class="glyphicon glyphicon-calendar"></span></span>
<?php echo form_input(array(
'name'=>'open_date',
'id'=>'open_date',
'class'=>'form-control input-sm datepicker',
'value'=>date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($cash_ups_info->open_date)))
);?>
</div>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_open_employee'), 'open_employee', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-6'>
<?php echo form_dropdown('open_employee_id', $employees, $cash_ups_info->open_employee_id, 'id="open_employee_id" class="form-control"');?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_open_amount_cash'), 'open_amount_cash', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-4'>
<div class="input-group input-group-sm">
<?php if (!currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
<?php echo form_input(array(
'name'=>'open_amount_cash',
'id'=>'open_amount_cash',
'class'=>'form-control input-sm',
'value'=>to_currency_no_money($cash_ups_info->open_amount_cash))
);?>
<?php if (currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
</div>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_transfer_amount_cash'), 'transfer_amount_cash', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-4'>
<div class="input-group input-group-sm">
<?php if (!currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
<?php echo form_input(array(
'name'=>'transfer_amount_cash',
'id'=>'transfer_amount_cash',
'class'=>'form-control input-sm',
'value'=>to_currency_no_money($cash_ups_info->transfer_amount_cash))
);?>
<?php if (currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
</div>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_close_date'), 'close_date', array('class'=>'required control-label col-xs-3')); ?>
<div class='col-xs-6'>
<div class="input-group">
<span class="input-group-addon input-sm"><span class="glyphicon glyphicon-calendar"></span></span>
<?php echo form_input(array(
'name'=>'close_date',
'id'=>'close_date',
'class'=>'form-control input-sm datepicker',
'value'=>date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($cash_ups_info->close_date)))
);?>
</div>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_close_employee'), 'close_employee', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-6'>
<?php echo form_dropdown('close_employee_id', $employees, $cash_ups_info->close_employee_id, 'id="close_employee_id" class="form-control"');?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_closed_amount_cash'), 'closed_amount_cash', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-4'>
<div class="input-group input-group-sm">
<?php if (!currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
<?php echo form_input(array(
'name'=>'closed_amount_cash',
'id'=>'closed_amount_cash',
'class'=>'form-control input-sm',
'value'=>to_currency_no_money($cash_ups_info->closed_amount_cash))
);?>
<?php if (currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
</div>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_note'), 'note', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-6'>
<?php echo form_checkbox(array(
'name'=>'note',
'id'=>'note',
'value'=>0,
'checked'=>($cash_ups_info->note) ? 1 : 0)
);?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_closed_amount_card'), 'closed_amount_card', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-4'>
<div class="input-group input-group-sm">
<?php if (!currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
<?php echo form_input(array(
'name'=>'closed_amount_card',
'id'=>'closed_amount_card',
'class'=>'form-control input-sm',
'value'=>to_currency_no_money($cash_ups_info->closed_amount_card))
);?>
<?php if (currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
</div>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_closed_amount_check'), 'closed_amount_check', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-4'>
<div class="input-group input-group-sm">
<?php if (!currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
<?php echo form_input(array(
'name'=>'closed_amount_check',
'id'=>'closed_amount_check',
'class'=>'form-control input-sm',
'value'=>to_currency_no_money($cash_ups_info->closed_amount_check))
);?>
<?php if (currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
</div>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_closed_amount_total'), 'closed_amount_total', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-4'>
<div class="input-group input-group-sm">
<?php if (!currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
<?php echo form_input(array(
'name'=>'closed_amount_total',
'id'=>'closed_amount_total',
'readonly'=>'true',
'class'=>'form-control input-sm',
'value'=>to_currency_no_money($cash_ups_info->closed_amount_total)
));?>
<?php if (currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
</div>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_description'), 'description', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-6'>
<?php echo form_textarea(array(
'name'=>'description',
'id'=>'description',
'class'=>'form-control input-sm',
'value'=>$cash_ups_info->description)
);?>
</div>
</div>
<?php
if(!empty($cash_ups_info->cashup_id))
{
?>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('cashups_is_deleted').':', 'deleted', array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-5'>
<?php echo form_checkbox(array(
'name'=>'deleted',
'id'=>'deleted',
'value'=>1,
'checked'=>($cash_ups_info->deleted) ? 1 : 0)
);?>
</div>
</div>
<?php
}
?>
</fieldset>
<?php echo form_close(); ?>
<script type='text/javascript'>
//validation and submit handling
$(document).ready(function()
{
<?php $this->load->view('partial/datepicker_locale'); ?>
$('#open_date').datetimepicker({
format: "<?php echo dateformat_bootstrap($this->config->item('dateformat')) . ' ' . dateformat_bootstrap($this->config->item('timeformat'));?>",
startDate: "<?php echo date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), mktime(0, 0, 0, 1, 1, 2010));?>",
<?php
$t = $this->config->item('timeformat');
$m = $t[strlen($t)-1];
if( strpos($this->config->item('timeformat'), 'a') !== false || strpos($this->config->item('timeformat'), 'A') !== false )
{
?>
showMeridian: true,
<?php
}
else
{
?>
showMeridian: false,
<?php
}
?>
minuteStep: 1,
autoclose: true,
todayBtn: true,
todayHighlight: true,
bootcssVer: 3,
language: '<?php echo current_language_code(); ?>'
});
$('#close_date').datetimepicker({
format: "<?php echo dateformat_bootstrap($this->config->item('dateformat')) . ' ' . dateformat_bootstrap($this->config->item('timeformat'));?>",
startDate: "<?php echo date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), mktime(0, 0, 0, 1, 1, 2010));?>",
<?php
$t = $this->config->item('timeformat');
$m = $t[strlen($t)-1];
if( strpos($this->config->item('timeformat'), 'a') !== false || strpos($this->config->item('timeformat'), 'A') !== false )
{
?>
showMeridian: true,
<?php
}
else
{
?>
showMeridian: false,
<?php
}
?>
minuteStep: 1,
autoclose: true,
todayBtn: true,
todayHighlight: true,
bootcssVer: 3,
language: '<?php echo current_language_code(); ?>'
});
$('#open_amount_cash, #transfer_amount_cash, #closed_amount_cash, #closed_amount_card, #closed_amount_check').keyup(function() {
$.post("<?php echo site_url($controller_name . '/ajax_cashup_total')?>", {
'open_amount_cash': $('#open_amount_cash').val(),
'transfer_amount_cash': $('#transfer_amount_cash').val(),
'closed_amount_cash': $('#closed_amount_cash').val(),
'closed_amount_card': $('#closed_amount_card').val(),
'closed_amount_check': $('#closed_amount_check').val()
},
function(response) {
$('#closed_amount_total').val(response.total);
},
'json'
);
});
var submit_form = function()
{
$(this).ajaxSubmit(
{
success: function(response)
{
dialog_support.hide();
table_support.handle_submit('<?php echo site_url('cashups'); ?>', response);
},
dataType: 'json'
});
};
$('#cashups_edit_form').validate($.extend(
{
submitHandler: function(form)
{
submit_form.call(form);
},
rules:
{
},
messages:
{
open_date:
{
required: '<?php echo $this->lang->line('cashups_date_required'); ?>'
},
close_date:
{
required: '<?php echo $this->lang->line('cashups_date_required'); ?>'
},
amount:
{
required: '<?php echo $this->lang->line('cashups_amount_required'); ?>',
number: '<?php echo $this->lang->line('cashups_amount_number'); ?>'
}
}
}, form_support.error));
});
</script>

View File

@@ -0,0 +1,63 @@
<?php $this->load->view("partial/header"); ?>
<script type="text/javascript">
$(document).ready(function()
{
// when any filter is clicked and the dropdown window is closed
$('#filters').on('hidden.bs.select', function(e) {
table_support.refresh();
});
// load the preset datarange picker
<?php $this->load->view('partial/daterangepicker'); ?>
$("#daterangepicker").on('apply.daterangepicker', function(ev, picker) {
table_support.refresh();
});
<?php $this->load->view('partial/bootstrap_tables_locale'); ?>
table_support.init({
resource: '<?php echo site_url($controller_name);?>',
headers: <?php echo $table_headers; ?>,
pageSize: <?php echo $this->config->item('lines_per_page'); ?>,
uniqueId: 'cashup_id',
queryParams: function() {
return $.extend(arguments[0], {
start_date: start_date,
end_date: end_date,
filters: $("#filters").val() || [""]
});
}
});
});
</script>
<?php $this->load->view('partial/print_receipt', array('print_after_sale'=>false, 'selected_printer'=>'takings_printer')); ?>
<div id="title_bar" class="print_hide btn-toolbar">
<button onclick="javascript:printdoc()" class='btn btn-info btn-sm pull-right'>
<span class="glyphicon glyphicon-print">&nbsp;</span><?php echo $this->lang->line('common_print'); ?>
</button>
<button class='btn btn-info btn-sm pull-right modal-dlg' data-btn-submit='<?php echo $this->lang->line('common_submit') ?>' data-href='<?php echo site_url($controller_name."/view"); ?>'
title='<?php echo $this->lang->line($controller_name.'_new'); ?>'>
<span class="glyphicon glyphicon-tags">&nbsp</span><?php echo $this->lang->line($controller_name . '_new'); ?>
</button>
</div>
<div id="toolbar">
<div class="pull-left form-inline" role="toolbar">
<button id="delete" class="btn btn-default btn-sm print_hide">
<span class="glyphicon glyphicon-trash">&nbsp</span><?php echo $this->lang->line("common_delete");?>
</button>
<?php echo form_input(array('name'=>'daterangepicker', 'class'=>'form-control input-sm', 'id'=>'daterangepicker')); ?>
<?php echo form_multiselect('filters[]', $filters, '', array('id'=>'filters', 'data-none-selected-text'=>$this->lang->line('common_none_selected_text'), 'class'=>'selectpicker show-menu-arrow', 'data-selected-text-format'=>'count > 1', 'data-style'=>'btn-default btn-sm', 'data-width'=>'fit')); ?>
</div>
</div>
<div id="table_holder">
<table id="table"></table>
</div>
<?php $this->load->view("partial/footer"); ?>

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB