Overview

Namespaces

  • emberlabs
    • Barcode
  • None

Classes

  • Appconfig
  • Barcode_lib
  • Config
  • Customer
  • Customer_rewards
  • Customers
  • Detailed_receivings
  • Detailed_sales
  • Dinner_table
  • Email_lib
  • emberlabs\Barcode\BarcodeBase
  • emberlabs\Barcode\Code128
  • emberlabs\Barcode\Code39
  • emberlabs\Barcode\Ean13
  • emberlabs\Barcode\Ean8
  • Employee
  • Employees
  • Giftcard
  • Giftcards
  • Home
  • Inventory
  • Inventory_low
  • Inventory_summary
  • Item
  • Item_kit
  • Item_kit_items
  • Item_kits
  • Item_lib
  • Item_quantity
  • Item_taxes
  • Items
  • Login
  • Mailchimp_lib
  • MailchimpConnector
  • Messages
  • Module
  • MY_Lang
  • No_Access
  • Person
  • Persons
  • Receiving
  • Receiving_lib
  • Receivings
  • Report
  • Reports
  • Rewards
  • Rounding_code
  • Sale
  • Sale_lib
  • Sale_suspended
  • Sales
  • Secure_Controller
  • Sms_lib
  • Specific_customer
  • Specific_discount
  • Specific_employee
  • Stock_location
  • Summary_categories
  • Summary_customers
  • Summary_discounts
  • Summary_employees
  • Summary_items
  • Summary_payments
  • Summary_report
  • Summary_sales
  • Summary_suppliers
  • Summary_taxes
  • Supplier
  • Suppliers
  • Tax
  • Tax_lib
  • Taxes
  • Token
  • Token_customer
  • Token_invoice_count
  • Token_invoice_sequence
  • Token_lib
  • Token_quote_sequence
  • Token_suspended_invoice_count
  • Token_year_invoice_count
  • Tracking_lib

Functions

  • currency_side
  • current_language
  • current_language_code
  • dateformat_bootstrap
  • dateformat_momentjs
  • db_log_queries
  • get_customer_data_row
  • get_customer_manage_table_headers
  • get_giftcard_data_row
  • get_giftcards_manage_table_headers
  • get_item_data_row
  • get_item_kit_data_row
  • get_item_kits_manage_table_headers
  • get_items_manage_table_headers
  • get_people_manage_table_headers
  • get_person_data_row
  • get_sale_data_last_row
  • get_sale_data_row
  • get_sales_manage_payments_summary
  • get_sales_manage_table_headers
  • get_supplier_data_row
  • get_suppliers_manage_table_headers
  • get_tax_data_row
  • get_taxes_manage_table_headers
  • load_config
  • load_language_files
  • load_stats
  • parse_decimals
  • pdf_create
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • to_currency
  • to_currency_no_money
  • to_decimals
  • to_quantity_decimals
  • to_tax_decimals
  • totals_decimals
  • transform_headers
  • transform_headers_readonly
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once("Secure_Controller.php");

class Receivings extends Secure_Controller
{
    public function __construct()
    {
        parent::__construct('receivings');

        $this->load->library('receiving_lib');
        $this->load->library('barcode_lib');
    }

    public function index()
    {
        $this->_reload();
    }

    public function item_search()
    {
        $suggestions = $this->Item->get_search_suggestions($this->input->get('term'), array('search_custom' => FALSE, 'is_deleted' => FALSE), TRUE);
        $suggestions = array_merge($suggestions, $this->Item_kit->get_search_suggestions($this->input->get('term')));

        $suggestions = $this->xss_clean($suggestions);

        echo json_encode($suggestions);
    }

    public function stock_item_search()
    {
        $suggestions = $this->Item->get_stock_search_suggestions($this->input->get('term'), array('search_custom' => FALSE, 'is_deleted' => FALSE), TRUE);
        $suggestions = array_merge($suggestions, $this->Item_kit->get_search_suggestions($this->input->get('term')));

        $suggestions = $this->xss_clean($suggestions);

        echo json_encode($suggestions);
    }

    public function select_supplier()
    {
        $supplier_id = $this->input->post('supplier');
        if($this->Supplier->exists($supplier_id))
        {
            $this->receiving_lib->set_supplier($supplier_id);
        }

        $this->_reload();
    }

    public function change_mode()
    {
        $stock_destination = $this->input->post('stock_destination');
        $stock_source = $this->input->post('stock_source');

        if((!$stock_source || $stock_source == $this->receiving_lib->get_stock_source()) &&
            (!$stock_destination || $stock_destination == $this->receiving_lib->get_stock_destination()))
        {
            $this->receiving_lib->clear_reference();
            $mode = $this->input->post('mode');
            $this->receiving_lib->set_mode($mode);
        }
        elseif($this->Stock_location->is_allowed_location($stock_source, 'receivings'))
        {
            $this->receiving_lib->set_stock_source($stock_source);
            $this->receiving_lib->set_stock_destination($stock_destination);
        }

        $this->_reload();
    }
    
    public function set_comment()
    {
        $this->receiving_lib->set_comment($this->input->post('comment'));
    }

    public function set_print_after_sale()
    {
        $this->receiving_lib->set_print_after_sale($this->input->post('recv_print_after_sale'));
    }
    
    public function set_reference()
    {
        $this->receiving_lib->set_reference($this->input->post('recv_reference'));
    }
    
    public function add()
    {
        $data = array();

        $mode = $this->receiving_lib->get_mode();
        $item_id_or_number_or_item_kit_or_receipt = $this->input->post('item');
        $quantity = ($mode == 'receive' || $mode == 'requisition') ? 1 : -1;
        $item_location = $this->receiving_lib->get_stock_source();

        if($mode == 'return' && $this->Receiving->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt))
        {
            $this->receiving_lib->return_entire_receiving($item_id_or_number_or_item_kit_or_receipt);
        }
        elseif($this->Item_kit->is_valid_item_kit($item_id_or_number_or_item_kit_or_receipt))
        {
            $this->receiving_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt, $item_location);
        }
        elseif(!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location))
        {
            $data['error'] = $this->lang->line('receivings_unable_to_add_item');
        }

        $this->_reload($data);
    }

    public function edit_item($item_id)
    {
        $data = array();

        $this->form_validation->set_rules('price', 'lang:items_price', 'required|callback_numeric');
        $this->form_validation->set_rules('quantity', 'lang:items_quantity', 'required|callback_numeric');
        $this->form_validation->set_rules('discount', 'lang:items_discount', 'required|callback_numeric');

        $description = $this->input->post('description');
        $serialnumber = $this->input->post('serialnumber');
        $price = parse_decimals($this->input->post('price'));
        $quantity = parse_decimals($this->input->post('quantity'));
        $discount = parse_decimals($this->input->post('discount'));
        $item_location = $this->input->post('location');

        if($this->form_validation->run() != FALSE)
        {
            $this->receiving_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $price);
        }
        else
        {
            $data['error']=$this->lang->line('receivings_error_editing_item');
        }

        $this->_reload($data);
    }
    
    public function edit($receiving_id)
    {
        $data = array();

        $data['suppliers'] = array('' => 'No Supplier');
        foreach($this->Supplier->get_all()->result() as $supplier)
        {
            $data['suppliers'][$supplier->person_id] = $this->xss_clean($supplier->first_name . ' ' . $supplier->last_name);
        }
    
        $data['employees'] = array();
        foreach ($this->Employee->get_all()->result() as $employee)
        {
            $data['employees'][$employee->person_id] = $this->xss_clean($employee->first_name . ' '. $employee->last_name);
        }
    
        $receiving_info = $this->xss_clean($this->Receiving->get_info($receiving_id)->row_array());
        $data['selected_supplier_name'] = !empty($receiving_info['supplier_id']) ? $receiving_info['company_name'] : '';
        $data['selected_supplier_id'] = $receiving_info['supplier_id'];
        $data['receiving_info'] = $receiving_info;
    
        $this->load->view('receivings/form', $data);
    }

    public function delete_item($item_number)
    {
        $this->receiving_lib->delete_item($item_number);

        $this->_reload();
    }
    
    public function delete($receiving_id = -1, $update_inventory = TRUE) 
    {
        $employee_id = $this->Employee->get_logged_in_employee_info()->person_id;
        $receiving_ids = $receiving_id == -1 ? $this->input->post('ids') : array($receiving_id);
    
        if($this->Receiving->delete_list($receiving_ids, $employee_id, $update_inventory))
        {
            echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('receivings_successfully_deleted') . ' ' .
                            count($receiving_ids) . ' ' . $this->lang->line('receivings_one_or_multiple'), 'ids' => $receiving_ids));
        }
        else
        {
            echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('receivings_cannot_be_deleted')));
        }
    }

    public function remove_supplier()
    {
        $this->receiving_lib->clear_reference();
        $this->receiving_lib->remove_supplier();

        $this->_reload();
    }

    public function complete()
    {
        $data = array();
        
        $data['cart'] = $this->receiving_lib->get_cart();
        $data['total'] = $this->receiving_lib->get_total();
        $data['receipt_title'] = $this->lang->line('receivings_receipt');
        $data['transaction_time'] = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'));
        $data['mode'] = $this->receiving_lib->get_mode();
        $data['comment'] = $this->receiving_lib->get_comment();
        $data['reference'] = $this->receiving_lib->get_reference();
        $data['payment_type'] = $this->input->post('payment_type');
        $data['show_stock_locations'] = $this->Stock_location->show_locations('receivings');
        $data['stock_location'] = $this->receiving_lib->get_stock_source();
        if($this->input->post('amount_tendered') != NULL)
        {
            $data['amount_tendered'] = $this->input->post('amount_tendered');
            $data['amount_change'] = to_currency($data['amount_tendered'] - $data['total']);
        }
        
        $employee_id = $this->Employee->get_logged_in_employee_info()->person_id;
        $employee_info = $this->Employee->get_info($employee_id);
        $data['employee'] = $employee_info->first_name . ' ' . $employee_info->last_name;

        $supplier_info = '';
        $supplier_id = $this->receiving_lib->get_supplier();
        if($supplier_id != -1)
        {
            $supplier_info = $this->Supplier->get_info($supplier_id);
            $data['supplier'] = $supplier_info->company_name;
            $data['first_name'] = $supplier_info->first_name;
            $data['last_name'] = $supplier_info->last_name;
            $data['supplier_email'] = $supplier_info->email;
            $data['supplier_address'] = $supplier_info->address_1;
            if(!empty($supplier_info->zip) or !empty($supplier_info->city))
            {
                $data['supplier_location'] = $supplier_info->zip . ' ' . $supplier_info->city;              
            }
            else
            {
                $data['supplier_location'] = '';
            }
        }

        //SAVE receiving to database
        $data['receiving_id'] = 'RECV ' . $this->Receiving->save($data['cart'], $supplier_id, $employee_id, $data['comment'], $data['reference'], $data['payment_type'], $data['stock_location']);

        $data = $this->xss_clean($data);

        if($data['receiving_id'] == 'RECV -1')
        {
            $data['error_message'] = $this->lang->line('receivings_transaction_failed');
        }
        else
        {
            $data['barcode'] = $this->barcode_lib->generate_receipt_barcode($data['receiving_id']);             
        }

        $data['print_after_sale'] = $this->receiving_lib->is_print_after_sale();

        $this->load->view("receivings/receipt",$data);

        $this->receiving_lib->clear_all();
    }

    public function requisition_complete()
    {
        if($this->receiving_lib->get_stock_source() != $this->receiving_lib->get_stock_destination()) 
        {
            foreach($this->receiving_lib->get_cart() as $item)
            {
                $this->receiving_lib->delete_item($item['line']);
                $this->receiving_lib->add_item($item['item_id'], $item['quantity'], $this->receiving_lib->get_stock_destination());
                $this->receiving_lib->add_item($item['item_id'], -$item['quantity'], $this->receiving_lib->get_stock_source());
            }
            
            $this->complete();
        }
        else 
        {
            $data['error'] = $this->lang->line('receivings_error_requisition');

            $this->_reload($data);  
        }
    }
    
    public function receipt($receiving_id)
    {
        $receiving_info = $this->Receiving->get_info($receiving_id)->row_array();
        $this->receiving_lib->copy_entire_receiving($receiving_id);
        $data['cart'] = $this->receiving_lib->get_cart();
        $data['total'] = $this->receiving_lib->get_total();
        $data['mode'] = $this->receiving_lib->get_mode();
        $data['receipt_title'] = $this->lang->line('receivings_receipt');
        $data['transaction_time'] = date($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), strtotime($receiving_info['receiving_time']));
        $data['show_stock_locations'] = $this->Stock_location->show_locations('receivings');
        $data['payment_type'] = $receiving_info['payment_type'];
        $data['reference'] = $this->receiving_lib->get_reference();
        $data['receiving_id'] = 'RECV ' . $receiving_id;
        $data['barcode'] = $this->barcode_lib->generate_receipt_barcode($data['receiving_id']);
        $employee_info = $this->Employee->get_info($receiving_info['employee_id']);
        $data['employee'] = $employee_info->first_name . ' ' . $employee_info->last_name;

        $supplier_id = $this->receiving_lib->get_supplier();
        if($supplier_id != -1)
        {
            $supplier_info = $this->Supplier->get_info($supplier_id);
            $data['supplier'] = $supplier_info->company_name;
            $data['first_name'] = $supplier_info->first_name;
            $data['last_name'] = $supplier_info->last_name;
            $data['supplier_email'] = $supplier_info->email;
            $data['supplier_address'] = $supplier_info->address_1;
            if(!empty($supplier_info->zip) or !empty($supplier_info->city))
            {
                $data['supplier_location'] = $supplier_info->zip . ' ' . $supplier_info->city;              
            }
            else
            {
                $data['supplier_location'] = '';
            }
        }

        $data['print_after_sale'] = FALSE;

        $data = $this->xss_clean($data);
        
        $this->load->view("receivings/receipt", $data);

        $this->receiving_lib->clear_all();
    }

    private function _reload($data = array())
    {
        $data['cart'] = $this->receiving_lib->get_cart();
        $data['modes'] = array('receive' => $this->lang->line('receivings_receiving'), 'return' => $this->lang->line('receivings_return'));
        $data['mode'] = $this->receiving_lib->get_mode();
        $data['stock_locations'] = $this->Stock_location->get_allowed_locations('receivings');
        $data['show_stock_locations'] = count($data['stock_locations']) > 1;
        if($data['show_stock_locations']) 
        {
            $data['modes']['requisition'] = $this->lang->line('receivings_requisition');
            $data['stock_source'] = $this->receiving_lib->get_stock_source();
            $data['stock_destination'] = $this->receiving_lib->get_stock_destination();
        }

        $data['total'] = $this->receiving_lib->get_total();
        $data['items_module_allowed'] = $this->Employee->has_grant('items', $this->Employee->get_logged_in_employee_info()->person_id);
        $data['comment'] = $this->receiving_lib->get_comment();
        $data['reference'] = $this->receiving_lib->get_reference();
        $data['payment_options'] = $this->Receiving->get_payment_options();

        $supplier_id = $this->receiving_lib->get_supplier();
        $supplier_info = '';
        if($supplier_id != -1)
        {
            $supplier_info = $this->Supplier->get_info($supplier_id);
            $data['supplier'] = $supplier_info->company_name;
            $data['first_name'] = $supplier_info->first_name;
            $data['last_name'] = $supplier_info->last_name;
            $data['supplier_email'] = $supplier_info->email;
            $data['supplier_address'] = $supplier_info->address_1;
            if(!empty($supplier_info->zip) or !empty($supplier_info->city))
            {
                $data['supplier_location'] = $supplier_info->zip . ' ' . $supplier_info->city;              
            }
            else
            {
                $data['supplier_location'] = '';
            }
        }
        
        $data['print_after_sale'] = $this->receiving_lib->is_print_after_sale();

        $data = $this->xss_clean($data);

        $this->load->view("receivings/receiving", $data);
    }
    
    public function save($receiving_id = -1)
    {
        $newdate = $this->input->post('date');
        
        $date_formatter = date_create_from_format($this->config->item('dateformat') . ' ' . $this->config->item('timeformat'), $newdate);

        $receiving_data = array(
            'receiving_time' => $date_formatter->format('Y-m-d H:i:s'),
            'supplier_id' => $this->input->post('supplier_id') ? $this->input->post('supplier_id') : NULL,
            'employee_id' => $this->input->post('employee_id'),
            'comment' => $this->input->post('comment'),
            'reference' => $this->input->post('reference') != '' ? $this->input->post('reference') : NULL
        );
    
        if($this->Receiving->update($receiving_data, $receiving_id))
        {
            echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('receivings_successfully_updated'), 'id' => $receiving_id));
        }
        else
        {
            echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('receivings_unsuccessfully_updated'), 'id' => $receiving_id));
        }
    }

    public function cancel_receiving()
    {
        $this->receiving_lib->clear_all();

        $this->_reload();
    }
}
?>
API documentation generated by ApiGen