Codeigniter 3 php mysql prevent issuance of items more than what is in the database

i am creating an inventory system using codeigniter 3 and mysql, now i have the following areas in my inventory, warehouse/store Categories Suppliers items Batch Transactions/activities

the area i have issues with is Transactions, you can issue items from the stores, and the system subtracts/removes the Quantity of what has been issued, my main problem is to prevent issuance of excess items that are not in the store, i want when someone tries to issue items more than what is in the store the system to check the quantity of the selected item from the database and if the requested is more than what is in the store, no activity takes place and they should get a message like " Sorry, you cannot issue more than what is in the stores"

/**********MANAGE Transactions ********************/
    function transaction($param1 = '', $param2 = '', $param3 = '')
    {
        if ($this->session->userdata('admin_login') != 1)
            redirect('login', 'refresh');
        if ($param1 == 'create') {
            
        $data['transaction_date'] = $this->input->post('transaction_date');
        $data['item_id'] = $this->input->post('item_id');
        $data['batch_id'] = $this->input->post('batch_id');
        $data['store_id'] = $this->input->post('store_id');
        $data['remarks'] = $this->input->post('remarks');
        $data['quantity'] = $this->input->post('quantity');
            
          $this->db->insert('transactions', $data);
             $this->session->set_flashdata('flash_message' , get_phrase('items_issued_successfully'));
            //$this->session->set_flashdata('flash_message' , get_phrase('items_issued_not_successfully'));
            
            redirect(base_url() . 'index.php?admin/transaction', 'refresh');
        }
        
        if ($param1 == 'edit') {
              $data['transaction_date'] = $this->input->post('transaction_date');
        $data['item_id'] = $this->input->post('item_id');
        $data['batch_id'] = $this->input->post('batch_id');
        $data['store_id'] = $this->input->post('store_id');
        $data['remarks'] = $this->input->post('remarks');
        $data['quantity'] = $this->input->post('quantity');
           $this->db->where('transaction_id' , $param2);
            $this->db->update('transactions' , $data);
            $this->session->set_flashdata('flash_message' , get_phrase('activity_data_updated'));
            redirect(base_url() . 'index.php?admin/transaction', 'refresh');
        }

         if ($param1 == 'delete') {
            $this->db->where('transaction_id', $param2);
            $this->db->delete('transactions');
            
            $this->session->set_flashdata('flash_message' , get_phrase('activity_deleted_successfully'));
            redirect(base_url() . 'index.php?admin/transaction', 'refresh');
        }

        $page_data['transactions'] = $this->db->get('transactions')->result_array();
        $page_data['page_name']   = 'transaction';
        $page_data['page_title']  = get_phrase('manage_transactions');
        $this->load->view('backend/index', $page_data);
        
    }

here is my view

<div class="panel-body">

                <?php echo form_open(base_url() . 'admin/transaction/create/' , array('class' => 'form-horizontal form-groups-bordered validate ajax-submit', 'enctype' => 'multipart/form-data'));?>
                

                    <div class="form-group">
                        <label for="field-1" class="col-sm-4 control-label">
                            <?php echo get_phrase('transaction_date');?>
                        </label>

                        <div class="col-sm-7">
                        <input type="text" class="form-control datepicker" name="transaction_date"  data-validate="required" data-message-required="<?php echo get_phrase('value_required');?>" value="" autofocus>
                           
                        </div>

                    </div>

                    <div class="form-group">
                        <label for="field-1" class="col-sm-4 control-label">
                            <?php echo get_phrase('stock_item'); ?>
                        </label>

                        <div class="col-sm-7">
                            <select name="item_id" class="select2">
                                <option>
                                    <?php echo get_phrase('item'); ?>
                                </option>
                                <?php
	                            $items = $this->db->get('items')->result_array();
	                            foreach ($items as $row):
	                                ?>
                                    <option value="<?php echo $row['item_id']; ?>">
                                        <?php echo $row['name']; ?>
                                    </option>
                                    <?php endforeach; ?>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="field-1" class="col-sm-4 control-label">
                            <?php echo get_phrase('stock_batch'); ?>
                        </label>

                        <div class="col-sm-7">
                            <select name="batch_id" class="select2">
                                <option>
                                    <?php echo get_phrase('batch'); ?>
                                </option>
                                <?php
	                            $batches = $this->db->get('batches')->result_array();
	                            foreach ($batches as $row):
	                                ?>
                                    <option value="<?php echo $row['batch_id']; ?>">
                                        <?php echo $row['name']; ?>
                                    </option>
                                    <?php endforeach; ?>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="field-1" class="col-sm-4 control-label">
                            <?php echo get_phrase('storage_store'); ?>
                        </label>

                        <div class="col-sm-7">
                            <select name="store_id" class="select2">
                                <option>
                                    <?php echo get_phrase('store'); ?>
                                </option>
                                <?php
	                            $stores = $this->db->get('stores')->result_array();
	                            foreach ($stores as $row):
	                                ?>
                                    <option value="<?php echo $row['store_id']; ?>">
                                        <?php echo $row['name']; ?>
                                    </option>
                                    <?php endforeach; ?>
                            </select>
                        </div>
                    </div>
                   <!-- <div class="form-group">
                        <label for="field-1" class="col-sm-4 control-label">
                            <?php echo get_phrase('Transaction_type');?>
                        </label>

                        <div class="col-sm-7">
                            <div>
                                <label for="transaction_type1">
                                <input id="transaction_type1" class="uk-radio" type="radio" name="transaction_type" value="Received">
                                Incoming</label>
                               <br/>
                                <label for="transaction_type2">
                                <input id="transaction_type2" class="uk-radio" type="radio" name="transaction_type" value="Issued">
                                Outgoing</label>
                              <br/>
                                 <label for="transaction_type3">
                                <input id="transaction_type3" class="uk-radio" type="radio" name="transaction_type" value="Expired">
                               Expired</label>
                               <br/>
                                <label for="transaction_type4">
                                <input id="transaction_type4"  class="uk-radio" type="radio" name="transaction_type" value="Damaged">
                                Damaged</label>
                                <br>
                            </div>
                        </div>
                    </div> -->
                    
                    <div class="form-group">
                        <label for="field-1" class="col-sm-4 control-label">
                            <?php echo get_phrase('remarks');?>
                        </label>

                        <div class="col-sm-7">
                                <input type="text" class="form-control" name="remarks" value"">
                           
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="field-1" class="col-sm-4 control-label">
                            <?php echo get_phrase('quantity');?>
                        </label>

                        <div class="col-sm-7">
                                <input type="num" class="form-control" name="quantity" value"1.00" placeholder"1">
                           
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-4 col-sm-7">
                            <button type="submit" class="btn btn-info" id="submit-button">
                                <?php echo get_phrase('add_transaction');?>
                            </button>
                            <span id="preloader-form"></span>
                        </div>
                    </div>
                    <?php echo form_close();?>
            </div>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.