CodeIgniter Forums
Calculation does not work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Regional User Groups (https://forum.codeigniter.com/forumdisplay.php?fid=25)
+--- Thread: Calculation does not work (/showthread.php?tid=69308)



Calculation does not work - Germanikus - 11-02-2017

Hello,
how do i manage it, that the first send the values in the input field "edit_artikel_kartensumme" is calculated the same and also stored in the database.
The second time the query is sent, the value is saved to the database.

Controller:

PHP Code:
            public function rechnung($slug)
                {
                    
$header['header_warenkorb_artikels'] = $this->Warenkorb_model->header_warenkorb_artikels();
                    
$header['header_warenkorb_produckts'] = $this->Warenkorb_model->header_warenkorb_produckts();
                    
$data['get_rechnung'] = $this->Rechnung_model->get_rechnung($slug);
                    
$data['view_warenkorb'] = $this->Rechnung_model->view_warenkorb($slug);
                    
$data['select_shops'] = $this->Warenkorb_model->select_shops();
                    
$data['briefmarkes'] = $this->Admin_model->briefmarkes();
                    
$data['lands'] = $this->Admin_model->lands();
                    
$data['get_umsatze'] = $this->Rechnung_model->get_umsatze($slug);
                    
$this->load->view('templates/header'$header);
                    
$this->load->view('rechnung/rechnung'$data);
                    
$this->load->view('templates/footer');
                }

            public function 
update_rechnung()
                {
                    
$slug $this->input->post('edit_rechnung_id');
                    
$this->Rechnung_model->update_rechnung($slug);
                    
redirect('rechnung/rechnung/'.$slug);
                } 

Model:
PHP Code:
           public function update_rechnung($slug)
 
               {
 
                   foreach ($this->input->post('edit_artikel_id') as $artikel_id)
 
                       {
 
                           $this->db->set('tb_artikel_anzahl'$this->input->post('edit_karte_menge')[$artikel_id]);
 
                           $this->db->set('tb_artikel_preis'floatval(str_replace(',''.'$this->input->post('edit_karte_preis')[$artikel_id])), FALSE);
 
                           $this->db->set('tb_artikel_gesamt_preis'floatval(str_replace(',''.'$this->input->post('edit_karte_preis')[$artikel_id])) * $this->input->post('edit_karte_menge')[$artikel_id], FALSE);
 
                           $this->db->where('tb_artikel_rechnung'$slug);
 
                           $this->db->where('tb_artikel_id'$artikel_id);
 
                           $this->db->update('db_artikel');

 
                           // $this->db->set('tb_rechnung_betrag', 'tb_rechnung_betrag +'.floatval(str_replace(',', '.', $this->input->post('edit_karte_preis')[$artikel_id])) * $this->input->post('edit_karte_menge')[$artikel_id], FALSE);
 
                           $this->db->set('tb_rechnung_betrag'floatval(str_replace(',''.'$this->input->post('edit_artikel_kartensumme'))), FALSE);
 
                           $this->db->set('tb_rechnung_menge'$this->input->post('edit_karte_menge')[$artikel_id]);
 
                           $this->db->where('tb_rechnung_id'$slug);
 
                           $this->db->update('db_rechnung');
 
                       }
 
               

View:
PHP Code:
                <div class="row">
                    <
div class="col-md-1"><h4><label class="label label-success">#</label></h4></div>
                    
<div class="col-md-9"><h4><label class="label label-success">Karten Information</label></h4></div>
                    <
div class="col-md-1"><h4><label class="label label-success">Preis pro Stk.</label></h4></div>
                    <
div class="col-md-1"><h4><label class="label label-success">Aktion</label></h4></div>
                </
div>
<?
php foreach ($view_warenkorb as $warenkorb):
    
$kartensumme 0;
    
$sql "SELECT
                *
            FROM
                db_artikel
            WHERE
                db_artikel.tb_artikel_rechnung = "
.$warenkorb['tb_artikel_rechnung']."";
    
$query $this->db->query($sql);
    foreach (
$query->result() as $rechnen)
        {
            
$kartensumme $kartensumme floatval($rechnen->tb_artikel_preis $rechnen->tb_artikel_anzahl);
        }
?>
                <div class="row">
                    <input type="hidden" name="edit_artikel_kartensumme" value="<?php echo number_format($kartensumme,2,",","."); ?>">
                    <input type="hidden" name="edit_artikel_id[<?php echo $warenkorb['tb_artikel_id']; ?>]" value="<?php echo $warenkorb['tb_artikel_id']; ?>">
                    <div class="col-md-1"><input type="text" class="form-control input-sm" name="edit_karte_menge[<?php echo $warenkorb['tb_artikel_id']; ?>]" value="<?php echo $warenkorb['tb_artikel_anzahl']; ?>"></div>
                    <div class="col-md-1"><input type="text" class="form-control input-sm" value="<?php if($warenkorb['tb_artikel_karten_stats'] == 0) { echo"//"; } if($warenkorb['tb_artikel_karten_stats'] >  1) { ?><?php echo $warenkorb['tb_edition_kurzel']."-".$warenkorb['tb_sprache_kurzel'].$warenkorb['tb_edition_stats_nummer']; ?><?php ?>" disabled></div>
                    <div class="col-md-4"><input type="text" class="form-control input-sm" value="<?php if($warenkorb['tb_artikel_karten_stats'] == 0) { echo $warenkorb['tb_produckt_name']; ?><?php ?><?php if($warenkorb['tb_artikel_karten_stats'] >  1) { ?><?php echo kartenname($warenkorb['tb_ygo_karten_stats_name_de'], $warenkorb['tb_ygo_karten_stats_name_en'], $warenkorb['tb_sprache_id']); ?><?php ?>" disabled></div>
                    <div class="col-md-2"><input type="text" class="form-control input-sm" value="<?php switch($warenkorb['tb_auflage_id']) { case (1): break; case (2): echo $warenkorb['tb_auflage_name_de'].""; break; case (3): echo $warenkorb['tb_auflage_name_de'].""; default; break; } ?>" disabled></div>
                    <div class="col-md-1"><?php if($warenkorb['tb_artikel_karten_stats'] == 0) { ?><button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="<?php echo $warenkorb['tb_artikel_zustand']; ?>">&nbsp;<?php echo $warenkorb['tb_artikel_zustand']; ?></button><?php } if($warenkorb['tb_artikel_karten_stats'] >  1) { ?><button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="<?php echo $warenkorb['tb_qualitat_name']; ?>"><img src="<?php echo base_url(); ?>/assets/images/site/qualitat/<?php echo $warenkorb['tb_qualitat_id']; ?>.png"/>&nbsp;<?php echo $warenkorb['tb_qualitat_short']; ?></button><?php ?></td></div>
                    <div class="col-md-1"><?php if($warenkorb['tb_artikel_karten_stats'] == 0) { echo"//"; } if($warenkorb['tb_artikel_karten_stats'] >  1) { ?><button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="<?php echo $warenkorb['tb_rare_name']; ?>"><?php echo $warenkorb['tb_rare_short']; ?></button><?php ?></div>
                    <div class="col-md-1"><div class="input-group"><div class="input-group-addon">€</div><input type="text" class="form-control" name="edit_karte_preis[<?php echo $warenkorb['tb_artikel_id']; ?>]" value="<?php echo number_format($warenkorb['tb_artikel_preis'],2,",","."); ?>"></div></div>
                    <div class="col-md-1">//</div>
                </div>
<?php endforeach; ?>



RE: Calculation does not work - Paradinight - 11-02-2017

(11-02-2017, 11:22 PM)Germanikus Wrote: Hello,
how do i manage it, that the first send the values in the input field "edit_artikel_kartensumme" is calculated the same and also stored in the database.
The second time the query is sent, the value is saved to the database.

Controller:

PHP Code:
public function rechnung($slug)
 {
 
$header['header_warenkorb_artikels'] = $this->Warenkorb_model->header_warenkorb_artikels();
 
$header['header_warenkorb_produckts'] = $this->Warenkorb_model->header_warenkorb_produckts();
 
$data['get_rechnung'] = $this->Rechnung_model->get_rechnung($slug);
 
$data['view_warenkorb'] = $this->Rechnung_model->view_warenkorb($slug);
 
$data['select_shops'] = $this->Warenkorb_model->select_shops();
 
$data['briefmarkes'] = $this->Admin_model->briefmarkes();
 
$data['lands'] = $this->Admin_model->lands();
 
$data['get_umsatze'] = $this->Rechnung_model->get_umsatze($slug);
 
$this->load->view('templates/header'$header);
 
$this->load->view('rechnung/rechnung'$data);
 
$this->load->view('templates/footer');
 }

 public function 
update_rechnung()
 {
 
$slug $this->input->post('edit_rechnung_id');
 
$this->Rechnung_model->update_rechnung($slug);
 
redirect('rechnung/rechnung/'.$slug);
 } 

Model:
PHP Code:
           public function update_rechnung($slug)
 
               {
 
                   foreach ($this->input->post('edit_artikel_id') as $artikel_id)
 
                       {
 
                           $this->db->set('tb_artikel_anzahl'$this->input->post('edit_karte_menge')[$artikel_id]);
 
                           $this->db->set('tb_artikel_preis'floatval(str_replace(',''.'$this->input->post('edit_karte_preis')[$artikel_id])), FALSE);
 
                           $this->db->set('tb_artikel_gesamt_preis'floatval(str_replace(',''.'$this->input->post('edit_karte_preis')[$artikel_id])) * $this->input->post('edit_karte_menge')[$artikel_id], FALSE);
 
                           $this->db->where('tb_artikel_rechnung'$slug);
 
                           $this->db->where('tb_artikel_id'$artikel_id);
 
                           $this->db->update('db_artikel');

 
                           // $this->db->set('tb_rechnung_betrag', 'tb_rechnung_betrag +'.floatval(str_replace(',', '.', $this->input->post('edit_karte_preis')[$artikel_id])) * $this->input->post('edit_karte_menge')[$artikel_id], FALSE);
 
                           $this->db->set('tb_rechnung_betrag'floatval(str_replace(',''.'$this->input->post('edit_artikel_kartensumme'))), FALSE);
 
                           $this->db->set('tb_rechnung_menge'$this->input->post('edit_karte_menge')[$artikel_id]);
 
                           $this->db->where('tb_rechnung_id'$slug);
 
                           $this->db->update('db_rechnung');
 
                       }
 
               

View:
PHP Code:
<div class="row">
 <
div class="col-md-1"><h4><label class="label label-success">#</label></h4></div>
 
<div class="col-md-9"><h4><label class="label label-success">Karten Information</label></h4></div>
 <
div class="col-md-1"><h4><label class="label label-success">Preis pro Stk.</label></h4></div>
 <
div class="col-md-1"><h4><label class="label label-success">Aktion</label></h4></div>
 </
div>
<?
php foreach ($view_warenkorb as $warenkorb):
 
$kartensumme 0;
 
$sql "SELECT
 *
 FROM
 db_artikel
 WHERE
 db_artikel.tb_artikel_rechnung = "
.$warenkorb['tb_artikel_rechnung']."";
 
$query $this->db->query($sql);
 foreach (
$query->result() as $rechnen)
 {
 
$kartensumme $kartensumme floatval($rechnen->tb_artikel_preis $rechnen->tb_artikel_anzahl);
 }
?>
 <div class="row">
 <input type="hidden" name="edit_artikel_kartensumme" value="<?php echo number_format($kartensumme,2,",","."); ?>">
 <input type="hidden" name="edit_artikel_id[<?php echo $warenkorb['tb_artikel_id']; ?>]" value="<?php echo $warenkorb['tb_artikel_id']; ?>">
 <div class="col-md-1"><input type="text" class="form-control input-sm" name="edit_karte_menge[<?php echo $warenkorb['tb_artikel_id']; ?>]" value="<?php echo $warenkorb['tb_artikel_anzahl']; ?>"></div>
 <div class="col-md-1"><input type="text" class="form-control input-sm" value="<?php if($warenkorb['tb_artikel_karten_stats'] == 0) { echo"//"; } if($warenkorb['tb_artikel_karten_stats'] >  1) { ?><?php echo $warenkorb['tb_edition_kurzel']."-".$warenkorb['tb_sprache_kurzel'].$warenkorb['tb_edition_stats_nummer']; ?><?php ?>" disabled></div>
 <div class="col-md-4"><input type="text" class="form-control input-sm" value="<?php if($warenkorb['tb_artikel_karten_stats'] == 0) { echo $warenkorb['tb_produckt_name']; ?><?php ?><?php if($warenkorb['tb_artikel_karten_stats'] >  1) { ?><?php echo kartenname($warenkorb['tb_ygo_karten_stats_name_de'], $warenkorb['tb_ygo_karten_stats_name_en'], $warenkorb['tb_sprache_id']); ?><?php ?>" disabled></div>
 <div class="col-md-2"><input type="text" class="form-control input-sm" value="<?php switch($warenkorb['tb_auflage_id']) { case (1): break; case (2): echo $warenkorb['tb_auflage_name_de'].""; break; case (3): echo $warenkorb['tb_auflage_name_de'].""; default; break; } ?>" disabled></div>
 <div class="col-md-1"><?php if($warenkorb['tb_artikel_karten_stats'] == 0) { ?><button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="<?php echo $warenkorb['tb_artikel_zustand']; ?>">&nbsp;<?php echo $warenkorb['tb_artikel_zustand']; ?></button><?php } if($warenkorb['tb_artikel_karten_stats'] >  1) { ?><button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="<?php echo $warenkorb['tb_qualitat_name']; ?>"><img src="<?php echo base_url(); ?>/assets/images/site/qualitat/<?php echo $warenkorb['tb_qualitat_id']; ?>.png"/>&nbsp;<?php echo $warenkorb['tb_qualitat_short']; ?></button><?php ?></td></div>
 <div class="col-md-1"><?php if($warenkorb['tb_artikel_karten_stats'] == 0) { echo"//"; } if($warenkorb['tb_artikel_karten_stats'] >  1) { ?><button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="<?php echo $warenkorb['tb_rare_name']; ?>"><?php echo $warenkorb['tb_rare_short']; ?></button><?php ?></div>
 <div class="col-md-1"><div class="input-group"><div class="input-group-addon">€</div><input type="text" class="form-control" name="edit_karte_preis[<?php echo $warenkorb['tb_artikel_id']; ?>]" value="<?php echo number_format($warenkorb['tb_artikel_preis'],2,",","."); ?>"></div></div>
 <div class="col-md-1">//</div>
 </div>
<?php endforeach; ?>

It hurt to read it. Is it a real shopping site or a test site?


RE: Calculation does not work - Germanikus - 11-03-2017

neither one nor the other.