Jump to content


rdroguett's Content

There have been 13 items by rdroguett (Search limited from 18-October 18)


By content type

See this member's

Sort by                Order  

#148981 Issue whith export and print buttons

Posted by rdroguett on 25 January 2019 - 02:59 PM in Bugs / Issues

The data is lost, when your press the print or export button. I dont have any solutions when i send in get or post method.



#148980 Error Export Data

Posted by rdroguett on 25 January 2019 - 02:55 PM in Bugs / Issues

Similar conflict

https://www.groceryc...979#entry148979



#148979 Issue whith export and print buttons

Posted by rdroguett on 25 January 2019 - 02:54 PM in Bugs / Issues

I have a some problem. The post data lost when i press export or print action



#148974 Error Export Data

Posted by rdroguett on 25 January 2019 - 08:19 AM in Bugs / Issues

the only way work export data in my controller is use a hard value example

 

NOT WORK

    public function report_sales_for_code(){

        $ide_company    =   $this->session->userdata['logged_in']['ide_company'];
        $ide_user       =   $this->session->userdata['logged_in']['ide_user'];

        //$date_start     =   $this->input->post('rvc_date_in', TRUE);
        //$date_end       =   $this->input->post('rvc_date_out', TRUE);

        $this->session->set_flashdata('in',$this->input->post('rvc_date_in', TRUE)); 
        $this->session->set_flashdata('out',$this->input->post('rvc_date_out', TRUE));         
        
        $date_start = $this->session->flashdata('in');
        $date_end   = $this->session->flashdata('out');
        
        $crud = new grocery_CRUD();   
        $crud->set_theme('bootstrap-v4');
        $crud->set_model('custom_query_model');
        $crud->set_table('e_order');
        //$crud->set_primary_key('CODE');  

        $crud->basic_model->set_query_str("
            SELECT
            a.ide_order,
            b.code as code,
            b.name as name,
            sum(b.qty) as qty
            FROM e_order a,  e_product b, e_invoice_order e, e_invoice f
            WHERE a.ide_order = b.ide_order
            AND e.ide_order = a.ide_order
            and f.ide_invoice = e.ide_invoice
            and a.ide_order_status = 2
            and DATE_FORMAT(a.date,'%Y-%m-%d') BETWEEN '$date_start' AND '$date_end'
            and a.ide_company = $ide_company
            and f.status = 'Habilitado'
            group by code
            order by b.code asc");

        $crud->set_subject('Reporte de ventas por codigo: '.date("d/m/Y", strtotime($date_start)).' hasta '.date("d/m/Y", strtotime($date_end)).'');
        $crud->display_as('name','Producto');
        $crud->display_as('code','Codigo');
        $crud->display_as('qty','Cantidad');     
        $crud->columns('code','name','qty');
        //$crud->unset_operations();
        $crud->unset_add(); $crud->unset_edit(); $crud->unset_delete(); $crud->unset_read();
        $output = $crud->render();
        $this->_appservice_output($output);
    }

WORK

    public function report_sales_for_code(){

        $ide_company    =   $this->session->userdata['logged_in']['ide_company'];
        $ide_user       =   $this->session->userdata['logged_in']['ide_user'];   
        
        $date_start = '2019-01-01';
        $date_end   = '2019-01-01';
        
        $crud = new grocery_CRUD();   
        $crud->set_theme('bootstrap-v4');
        $crud->set_model('custom_query_model');
        $crud->set_table('e_order');
        //$crud->set_primary_key('CODE');  

        $crud->basic_model->set_query_str("
            SELECT
            a.ide_order,
            b.code as code,
            b.name as name,
            sum(b.qty) as qty
            FROM e_order a,  e_product b, e_invoice_order e, e_invoice f
            WHERE a.ide_order = b.ide_order
            AND e.ide_order = a.ide_order
            and f.ide_invoice = e.ide_invoice
            and a.ide_order_status = 2
            and DATE_FORMAT(a.date,'%Y-%m-%d') BETWEEN '$date_start' AND '$date_end'
            and a.ide_company = $ide_company
            and f.status = 'Habilitado'
            group by code
            order by b.code asc");

        $crud->set_subject('Reporte de ventas por codigo: '.date("d/m/Y", strtotime($date_start)).' hasta '.date("d/m/Y", strtotime($date_end)).'');
        $crud->display_as('name','Producto');
        $crud->display_as('code','Codigo');
        $crud->display_as('qty','Cantidad');     
        $crud->columns('code','name','qty');
        //$crud->unset_operations();
        $crud->unset_add(); $crud->unset_edit(); $crud->unset_delete(); $crud->unset_read();
        $output = $crud->render();
        $this->_appservice_output($output);
    }



#148972 Error Export Data

Posted by rdroguett on 24 January 2019 - 06:30 PM in Bugs / Issues

Where insert this

 

ini_set('display_errors', 'on');
error_reporting(E_ALL);

 

I put in index.php on the root folder but not work!




#148958 Setting Default Value for Hidden Field

Posted by rdroguett on 22 January 2019 - 04:15 AM in Grocery CRUD Enterprise

i have a some error alway is 0




#148898 Error Export Data

Posted by rdroguett on 03 January 2019 - 02:43 PM in Bugs / Issues

anyone can help me?




#148896 Error Export Data

Posted by rdroguett on 02 January 2019 - 05:42 AM in Bugs / Issues

Hi guys i have a little problem when i try export data using custom query...
not exporting nothing

   

  public function payment_received_date(){
         
        $date_start =  $this->input->post('in', TRUE);
        $date_end   =  $this->input->post('out', TRUE);
          
        $crud = new grocery_CRUD();
        $crud->set_theme('bootstrap-v4');
        $crud->set_model('custom_query_model');
        $crud->set_table('e_invoice');
        $crud->basic_model->set_query_str("
        SELECT  
        a.ide_invoice, 
        a.assigned_folio as Factura,  
        CONCAT('$', format(a.mount,0,'de_DE')) as Valor, 
        CASE WHEN NAME= 'EF' THEN CONCAT('$', format(SUM(b.mount),0,'de_DE')) ELSE 0 END EF, 
        CASE WHEN NAME= 'CH' THEN CONCAT('$', format(SUM(b.mount),0,'de_DE')) ELSE 0 END CH, 
        CASE WHEN NAME= 'CR' THEN CONCAT('$', format(SUM(b.mount),0,'de_DE')) ELSE 0 END CR, 
        CASE WHEN NAME= 'TC' THEN CONCAT('$', format(SUM(b.mount),0,'de_DE')) ELSE 0 END TC, 
        CASE WHEN NAME= 'NT' THEN CONCAT('$', format(SUM(b.mount),0,'de_DE')) ELSE 0 END NT, 
        a.date 
        FROM e_invoice a, e_invoice_traking b, e_payment_methods c                 
        WHERE b.assigned_folio = a.assigned_folio 
        AND b.ide_payment_methods = c.ide_payment_methods                 
        AND a.ide_company = 1
        AND DATE_FORMAT(a.date,'%Y-%m-%d') BETWEEN '$date_start' AND '$date_end' 
        GROUP BY a.ide_invoice, name


        UNION ALL


        SELECT
        tmp.ide_invoice,
        'TOTAL',
        CONCAT('$', format(sum(tmp.monto),0,'de_DE')),
        CONCAT('$', format(sum(tmp.EF),0,'de_DE')),
        CONCAT('$', format(sum(tmp.CH),0,'de_DE')),
        CONCAT('$', format(sum(tmp.CR),0,'de_DE')),
        CONCAT('$', format(sum(tmp.TC),0,'de_DE')),
        CONCAT('$', format(sum(tmp.NT),0,'de_DE')),
        tmp.date
        FROM
        (
        SELECT 
        a.ide_invoice, 
        a.assigned_folio, 
        a.mount monto, 
        CASE WHEN NAME= 'EF' THEN SUM(b.mount) ELSE 0 END EF,
        CASE WHEN NAME= 'CH' THEN SUM(b.mount) ELSE 0 END CH,
        CASE WHEN NAME= 'CR' THEN SUM(b.mount) ELSE 0 END CR,
        CASE WHEN NAME= 'TC' THEN SUM(b.mount) ELSE 0 END TC,
        CASE WHEN NAME= 'NT' THEN SUM(b.mount) ELSE 0 END NT,
        a.date
        FROM e_invoice a, e_invoice_traking b, e_payment_methods c WHERE b.assigned_folio = a.assigned_folio
        AND b.ide_payment_methods = c.ide_payment_methods 
        AND a.ide_company = '1'
        AND DATE_FORMAT(a.date,'%Y-%m-%d') BETWEEN '$date_start' AND '$date_end'
        GROUP BY a.ide_invoice, name
        ) tmp
        ");     


        $crud->set_subject('Reporte de pagos recibidos');
        $crud->display_as('assigned_folio','Factura');
        $crud->display_as('date','Fecha');
        $crud->columns('Factura','Valor','EF','CH','CR','TC','NT');
        $crud->unset_add();
        $crud->unset_delete();
        $crud->unset_edit();
        $crud->unset_read();
        $output = $crud->render();
        $this->_appservice_output($output);
    }

 

 

Display perfect but no export nothing... only i see a white page




#141740 CRUD + Autocomplete + Custom Input

Posted by rdroguett on 30 October 2018 - 02:05 PM in Extra coding / Plugins

Now my actual problem...
 
I want add autocomplete but not work, I'm not sure why but i need help... Check the code....
 
for add autocomplete i need the libs for this so i add the libs, then i need controller the call for use autocomplete
 
 
Step 1 add the libs and the function Jquery
    <!-- SCRIPTS + CODIGO AUTOCOMPLETADO -->
    <link rel="stylesheet" href="<?php echo base_url().'assets/css/jquery-ui.css'?>">
    <script src="<?php echo base_url().'assets/js/jquery-ui.js'?>" type="text/javascript"></script>      
    <script>

            $(document).ready(function(){
                //$('#product_code').autocomplete({
                $('.search').autocomplete({
                    source: "<?php echo site_url('blog/get_autocomplete'); ?>",
                    select: function (event, ui) {
                        $('[name="product_code[]"]').val(ui.item.label); 
                        $('[name="product_name[]"]').val(ui.item.name); 
                        $('[name="product_qty[]"]').val(ui.item.qty); 
                        $('[name="product_price[]"]').val(ui.item.price); 
                    }
                });
            });

    </script>
    <!-- FIN -->

I used a class called "SEARCH" for know how call the object and if you see the last code can see the class was added in all inputs

 

 

Step 2: Add a controller and model for call the data in the database

Controller very easy

The controller recieve the id and return de data
 

<?php
class Blog extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->load->model('product_model');
    }
  
    function get_autocomplete(){
        if (isset($_GET['term'])) {
            $result = $this->product_model->search_product($_GET['term']);
            if (count($result) > 0) {
            foreach ($result as $row)
                
                $arr_result[] = array(
                        'label' => $row->code,
                        'name'  => $row->name,
                        'qty'   => $row->qty,
                        'price' => $row->price,
                 );
            
                echo json_encode($arr_result);
            }
        }
    }
 
}

The model...

<?php
class Product_model extends CI_Model {

    function search_product($code){
        $this->db->like('code', $code, 'both');
        //$this->db->where('code', $code);
        $this->db->order_by('code', 'ASC');
        $this->db->limit(10);
        return $this->db->get('e_stock')->result();
    }
}

And now i can check if this work or not....
 

u6BFPZg.png

Works BUT no autocomplete the next boxes... BUT if i change the code not using array the method works... check

THE VIEW FOR AUTOCOMPLETE

    <!-- SCRIPTS + CODIGO AUTOCOMPLETADO -->
    <link rel="stylesheet" href="<?php echo base_url().'assets/css/jquery-ui.css'?>">
    <script src="<?php echo base_url().'assets/js/jquery-ui.js'?>" type="text/javascript"></script>      
    <script>

            $(document).ready(function(){
                //$('#product_code').autocomplete({
                $('.search').autocomplete({
                    source: "<?php echo site_url('blog/get_autocomplete'); ?>",
                    select: function (event, ui) {
                        $('[name="product_code"]').val(ui.item.label); 
                        $('[name="product_name"]').val(ui.item.name); 
                        $('[name="product_qty"]').val(ui.item.qty); 
                        $('[name="product_price"]').val(ui.item.price); 
                    }
                });
            });

    </script>
    <!-- FIN -->

THE VIEW FOR ADD MULTI ITEMS

<script>
        jQuery(document).ready(function(){
            jQuery('#add_number').on('click', function(e){
                e.preventDefault();
                var row = '<tr><td><input id="product_code" name="product_code" type="text" style="width: 100px;" class="form-control"></td><td><input id="product_name" name="product_name" type="text" class="form-control"></td><td><input id="product_qty" name="product_qty" type="text" style="width: 100px;" class="form-control"></td><td><input id="product_price" name="product_price" type="text" style="width: 100px;" class="form-control"></td><td><button class="remove_number btn btn-danger"><i class="el el-remove-circle"></i>&nbsp;Eliminar</button></td></tr>';
                //var row = '<tr><td><input id="product_code[]" name="product_code[]" type="text" style="width: 100px;" class="search form-control"></td><td><input id="product_name[]" name="product_name[]" type="text" class="form-control"></td><td><input id="product_qty[]" name="product_qty[]" type="text" style="width: 100px;" class="form-control"></td><td><input id="product_price[]" name="product_price[]" type="text" style="width: 100px;" class="form-control"></td><td><button class="remove_number btn btn-danger"><i class="el el-remove-circle"></i>&nbsp;Eliminar</button></td></tr>';
                    jQuery('#product_list tr:last').after(row);
                    register_remove_event();
                });
                    
                function register_remove_event(){
                    jQuery('#product_list button.remove_number').on('click', function (e) {
                    e.preventDefault();
                    if(jQuery('#product_list tr').length > 2){
                        jQuery(this).parents('tr').remove();
                    }
                });
            }
            register_remove_event();
            
        });
</script>

I remove the all array declarations in the input objects

THE CONTROLLER (THE CALLBACK ...)

    public function _callback_list_product($value = '', $primary_key = null){
        $this->db->where('ide_order', $primary_key);
        $products = $this->db->get('e_product')->result_array();
        $products[30] = array();

        $html = '
            <table id="product_list"> 
                <tr>
                    <th>Codigo</th><th>Nombre</th><th>Cantidad</th><th>Precio ($CLP)</th>
                </tr>';
                foreach($products as $product)
                {
                    if(!empty($product['code']))
                    {
                    $html.= '<tr>'. 
                        '<td><input id="product_code" name="product_code" type="text" value="'.$product["code"].'" style="width: 100px;" class="form-control"></td>'.
                        '<td><input id="product_name" name="product_name" type="text" value="'.$product["name"].'" class="form-control"></td>'. 
                        '<td><input id="product_qty" name="product_qty" type="text" value="'.$product["qty"].'" style="width: 100px;" class="form-control"></td>'. 
                        '<td><input id="product_price" name="product_price" type="text" value="'.$product["price"].'" style="width: 100px;" class="form-control"></td>'. 
                        
                        '<td><button class="remove_number btn btn-danger"><i class="el el-remove-circle"></i>&nbsp;Eliminar</button></td></tr>';
                    }
                    else
                    {
                    $html .='<tr>'.
                        '<td><input id="product_code" name="product_code" type="text" style="width: 100px;" class="form-control"></td>'.
                        '<td><input id="product_name" name="product_name" type="text" class="form-control"></td>'.
                        '<td><input id="product_qty" name="product_qty" type="text" style="width: 100px;" class="form-control"></td>'.
                        '<td><input id="product_price" name="product_price" type="text" style="width: 100px;" class="form-control"></td>'.
                            
                        '<td><button id="remove_number" class="remove_number btn btn-danger"><i class="el el-remove-circle"></i>&nbsp;Eliminar</button></td></tr></table>'.
                        '<button type="button" id="add_number" style="margin-top: 5px;" class="btn btn-secondary btn-success b10"><i class="el el-circle-arrow-right"></i>&nbsp;Agregar</button>';
                    }
                }
      

I remove the all array declaration and now check.. again ... not using a array</span></p>

 

hmzTvHp.png

 

Autocomplete works!! but not in array mode :(

it's not a solutions... i need help please...
 




#141739 CRUD + Autocomplete + Custom Input

Posted by rdroguett on 30 October 2018 - 01:39 PM in Extra coding / Plugins

Hi guys i want share parts of the code from my software, and request help for finished a some part

 

The software is used for control sales and quotations of a my company

 

bAmcXBZ.png

 

This module use a two tables no relationated but connected between

CREATE TABLE `e_order` (
  `ide_order` int(11) NOT NULL,
  `ide_customer` int(11) NOT NULL,
  `date` datetime NOT NULL,
  `ide_way_payment` int(1) NOT NULL DEFAULT '1',
  `status` int(11) NOT NULL DEFAULT '0',
  `ide_company` int(11) NOT NULL,
  `ide_type_payment` int(11) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `e_product` (
  `ide_product` int(11) NOT NULL,
  `code` varchar(45) NOT NULL,
  `name` varchar(45) NOT NULL,
  `qty` int(11) NOT NULL DEFAULT '0',
  `price` int(11) NOT NULL,
  `total` int(11) NOT NULL,
  `ide_order` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

If i want add items on  the order i used a callback

 

cf9VowK.png

 

Controller

    public function genera_orden($value = '', $primary_key = null){
        $date = date("Y-m-d H:i:s");

        $customer   = new SoapClient("http://www.appoctava.cl/ws/WebService.php?wsdl", $this->data['conexion']);
        foreach($this->token_model->validar_token() as $row)
        {
            $array  = array("TOKEN" => $row->token); 
            try{ 
                $result         = $customer->__SoapCall("validartokenext", $array); 
                $result_code    = $result[0]->DescripcionResultado; 
                if($result_code == 'TVAL'){
                    $crud = new grocery_CRUD();
                    $crud->set_theme('bootstrap-v4');
                    $crud->set_table('e_order');
                    $crud->where('e_order.ide_company',$this->session->userdata['logged_in']['ide_company']);
                    $crud->set_subject('Orden de compras');

                    $crud->callback_add_field('product', array($this, '_callback_list_product'));
                    $crud->callback_edit_field('product', array($this, '_callback_list_product'));
                    $crud->callback_read_field('product', array($this,'_callback_list_product'));

                    $crud->unset_columns(array('product','ide_company'));
                    
                    $crud->field_type('date', 'hidden', $date);
                    $crud->field_type('ide_company', 'hidden', $this->session->userdata['logged_in']['ide_company']);

                    $crud->callback_after_insert(array($this, '_callback_save_product'));
                    $crud->callback_after_delete(array($this,'_callback_delete_product'));
                    $crud->callback_before_update(array($this, '_callback_save_product'));

                    $crud->add_action('Emitir Factura', '', 'appservice/agrega_dte','ui-icon-plus');

                    $crud->display_as('ide_order','N° Orden de compra');
                    $crud->display_as('ide_customer','Receptor');
                    $crud->display_as('product','Producto(s)');
                    $crud->display_as('date','Fecha');
                    $crud->display_as('status','Estado');
                    $crud->display_as('bname','Nombre');
                    $crud->display_as('ide_way_payment','Forma de pago');
                    $crud->display_as('ide_type_payment','Plazo de pago');
                    
                    $crud->callback_column('status',array($this,'_callback_status_order'));
                    $crud->callback_field('bname',array($this,'_callback_bname'));
                    $crud->callback_column('date',array($this,'_callback_date_format'));
                    
                    $crud->fields('ide_customer','date','bname','product','ide_type_payment','ide_company');

                    $crud->set_relation('ide_customer','e_customer','bname');
                    $crud->set_relation('ide_way_payment','e_way_payment','name');
                    $crud->set_relation('ide_type_payment','e_type_payment','name');
                    
                    $crud->columns('ide_order','ide_customer','date','ide_way_payment','ide_type_payment','status');

                    $crud->add_fields('ide_customer','date','product','ide_way_payment','ide_type_payment','ide_company');
                    $crud->edit_fields('date','product','ide_way_payment','ide_type_payment','ide_company');

                    $output = $crud->render();
                    $this->_appservice_output($output);
                }else{
                    $this->obtener_token();
                    redirect(base_url('user/login'), 'refresh');
                }
            }catch(SoapFault $e){ 
                echo "Ups!! hubo un problema y no pudimos recuperar los datos.<br/>$e<hr/>"; 
            } 
        }
    }

Callback return the HTML

    public function _callback_list_product($value = '', $primary_key = null){
        $this->db->where('ide_order', $primary_key);
        $products = $this->db->get('e_product')->result_array();
        $products[30] = array();

        $html = '
            <table id="product_list"> 
                <tr>
                    <th>Codigo</th><th>Nombre</th><th>Cantidad</th><th>Precio ($CLP)</th>
                </tr>';
                foreach($products as $product)
                {
                    if(!empty($product['code']))
                    {
                    $html.= '<tr>'. 
                        //'<td><input id="product_code[]" name="product_code[]" type="text" value="'.$product["code"].'" style="width: 100px;" class="form-control"></td>'.
                        '<td><input id="product_code[]" name="product_code[]" type="text" value="'.$product["code"].'" style="width: 100px;" class="search form-control"></td>'.
                        '<td><input id="product_name[]" name="product_name[]" type="text" value="'.$product["name"].'" class="form-control"></td>'. 
                        '<td><input id="product_qty[]" name="product_qty[]" type="text" value="'.$product["qty"].'" style="width: 100px;" class="form-control"></td>'. 
                        '<td><input id="product_price[]" name="product_price[]" type="text" value="'.$product["price"].'" style="width: 100px;" class="form-control"></td>'. 
                        
                        '<td><button class="remove_number btn btn-danger"><i class="el el-remove-circle"></i>&nbsp;Eliminar</button></td></tr>';
                    }
                    else
                    {
                    $html .='<tr>'.
                        //'<td><input id="product_code[]" name="product_code[]" type="text" style="width: 100px;" class="form-control"></td>'.
                        '<td><input id="product_code[]" name="product_code[]" type="text" style="width: 100px;" class="search form-control"></td>'.
                        '<td><input id="product_name[]" name="product_name[]" type="text" class="form-control"></td>'.
                        '<td><input id="product_qty[]" name="product_qty[]" type="text" style="width: 100px;" class="form-control"></td>'.
                        '<td><input id="product_price[]" name="product_price[]" type="text" style="width: 100px;" class="form-control"></td>'.
                            
                        '<td><button id="remove_number" class="remove_number btn btn-danger"><i class="el el-remove-circle"></i>&nbsp;Eliminar</button></td></tr></table>'.
                        '<button type="button" id="add_number" style="margin-top: 5px;" class="btn btn-secondary btn-success b10"><i class="el el-circle-arrow-right"></i>&nbsp;Agregar</button>';
                    }
                }
        return $html;
    }

Check the input line was declared on array for add multi items 

 

Now i put the Callback for save the items

    public function _callback_save_product($post_array, $primary_key){
        $this->db->delete('e_product', array('ide_order' => $primary_key));
        $i = 0;
        $data = array();
        while(!empty($post_array["product_code"][$i]) ){
            $product = array(
                'code'      => $post_array["product_code"][$i],
                'name'      => $post_array["product_name"][$i],
                'qty'       => $post_array["product_qty"][$i],
                'price'     => $post_array["product_price"][$i],
                'total'     => ($post_array["product_qty"][$i]*$post_array["product_price"][$i]),
                'ide_order' => $primary_key
            );
            array_push($data, $product);
            $i++;
        }
        $this->db->insert_batch('e_product', $data);
    }

This method works fine... but i need multiple items not only one.. for fix this request i used jquery !! 

 

 

First i add the Jquery and the libs on my view... (_appservice_output);

 

 

View

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

<script>
        jQuery(document).ready(function(){
            jQuery('#add_number').on('click', function(e){
                e.preventDefault();
                //var row = '<tr><td><input id="product_code[]" name="product_code[]" type="text" style="width: 100px;" class="form-control"></td><td><input id="product_name[]" name="product_name[]" type="text" class="form-control"></td><td><input id="product_qty[]" name="product_qty[]" type="text" style="width: 100px;" class="form-control"></td><td><input id="product_price[]" name="product_price[]" type="text" style="width: 100px;" class="form-control"></td><td><button class="remove_number btn btn-danger"><i class="el el-remove-circle"></i>&nbsp;Eliminar</button></td></tr>';
                var row = '<tr><td><input id="product_code[]" name="product_code[]" type="text" style="width: 100px;" class="search form-control"></td><td><input id="product_name[]" name="product_name[]" type="text" class="form-control"></td><td><input id="product_qty[]" name="product_qty[]" type="text" style="width: 100px;" class="form-control"></td><td><input id="product_price[]" name="product_price[]" type="text" style="width: 100px;" class="form-control"></td><td><button class="remove_number btn btn-danger"><i class="el el-remove-circle"></i>&nbsp;Eliminar</button></td></tr>';
                    jQuery('#product_list tr:last').after(row);
                    register_remove_event();
                });
                    
                function register_remove_event(){
                    jQuery('#product_list button.remove_number').on('click', function (e) {
                    e.preventDefault();
                    if(jQuery('#product_list tr').length > 2){
                        jQuery(this).parents('tr').remove();
                    }
                });
            }
            register_remove_event();
            
        });
</script>

All this modification permit this new functionality in the software.. can add one or multiple items

 

mhRv0Mc.png

 

 

Works fine!!




#31497 grocery crud master-detail 1_n relation implementation

Posted by rdroguett on 21 September 2018 - 04:25 PM in General

This metho make problems with the edit options... please check




#16520 grocery crud master-detail 1_n relation implementation

Posted by rdroguett on 12 September 2018 - 09:21 PM in General

the problem is the position of the js in the proyect but i dont know hoy can i fixed




#16519 grocery crud master-detail 1_n relation implementation

Posted by rdroguett on 11 September 2018 - 05:47 PM in General

Nice code... buts in my model i have a trouble... but i never recive the parameters into de callback...

 

 

Tables

 

CREATE TABLE `e_order` (
  `ide_order` int(11) NOT NULL,
  `run` varchar(11) NOT NULL,
  `date` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `e_product` (
  `ide_product` int(11) NOT NULL,
  `code` varchar(45) NOT NULL,
  `name` varchar(45) NOT NULL,
  `price` int(11) NOT NULL,
  `ide_order` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 

 

    public function genera_orden(){
        $this->output->enable_profiler(TRUE);
        $this->load->model('token_model');
        $this->load->model('invoice_model');
        
        $customer   = new SoapClient("http://www.appoctava.cl/ws/WebService.php?wsdl", $this->data['conexion']);
        foreach($this->token_model->validar_token() as $row)
        {
            $array  = array("TOKEN" => $row->token); 
            try{ 
                $result         = $customer->__SoapCall("validartokenext", $array); 
                $result_code    = $result[0]->DescripcionResultado; 
                if($result_code == 'TVAL'){
                    $crud = new grocery_CRUD();
                    $crud->set_theme('datatables');
                    $crud->set_table('e_order');
                    $crud->set_subject('Orden de Compra');
                    $crud->fields('run', 'date', 'product');
                    $crud->callback_add_field('product', array($this, 'list_product'));


                    $crud->display_as('ide_user','Usuario');
                    $crud->display_as('run','Receptor');
                    $crud->display_as('product','Producto(s)');
                    
                    $crud->callback_before_insert(array($this, 'save_product'));
                    $crud->callback_before_update(array($this, 'save_product'));


                    $output = $crud->render();
                    $this->_appservice_output($output);
                }else{
                    echo "ERROR TOKEN";
                    $this->obtener_token();
                }
            }catch(SoapFault $e){ 
                echo "Ups!! hubo un problema y no pudimos recuperar los datos.<br/>$e<hr/>"; 
            } 
        }
    }

function save_product($post_array, $primary_key){        
$this->db->delete('e_product', array('ide_order' => $primary_key));
        $i = 0;
        $data = array();
        while(!empty($post_array["product_code"][$i]) ){
            $product = array(
                'code'      => $post_array["product_code"][$i],
                'name'      => $post_array["product_name"][$i],
                'price'     => $post_array["product_price"][$i],
                'ide_order' => $primary_key
            );
            array_push($data, $product);
            $i++;
        }
        $this->db->insert_batch('e_product', $data);
    }
function list_product($value = '', $primary_key = null){        
$this->db->where('ide_order', $primary_key);
        $products = $this->db->get('e_product')->result_array();
        $products[1] = array();
        $html = '
            <table id="product_list"> 
                <tr>
                    <th>CODIGO</th><th>NOMBRE ARTICULO</th><th>PRECIO ($CLP)</th>
                </tr>';
                foreach ($products as $product){
                if(!empty($product["code"]))
                $html.= '<tr>'. 
                        '<td><input name="product_code[]" type="text" value="'.$product["code"].'"></td>'. 
                        '<td><input name="product_name[]" type="text" value="'.$product["name"].'"></td>'. 
                        '<td><input name="product_price[]" type="text" value="'.$product["price"].'"></td>'. 
                        '<td><button class="remove_number btn btn-danger">Eliminar</button></td></tr>';
                }
                $html .='<tr>'.
                        '<td><input name="product_code[]" type="text"></td>'.
                        '<td><input name="product_name[]" type="text"></td>'.
                        '<td><input name="product_price[]" type="text"></td>'.
                        '<td><button id="remove_number" class="remove_number btn btn-danger">Eliminar</button></td></tr></table>'.
                        '<button type="button" id="add_number" class="cancel-button ui-input-button ui-button ui-widget ui-state-default ui-corner-all ui-state-hover" style="width: 100px; margin:20px 0px;">Agregar</button>';
                return $html;
    }