• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Models Remember Vars?

#1
[eluser]datguru[/eluser]
Hi there guys, sorry been abusing the forum a bit here just trying to get use to using these models seem to be causing me more trouble at the moment (my fault Smile). Has anyone had any problems with using a model then changing the variables and trying to do another query... Id you look in my code below I update the product parts table but I then need to access it again to calculate the new prices for the product. For some reason though it remembers the type setting which I don't want it to because I need it to recalculate everything not just the raw material parts. Is there a way to flush the model so it forgets about my previous settings or does it not actually remember it and I am actually doing something more stupid?

Thanks

Regards


Code:
//Update All Product Tables so they have new pricing of raw material
        $this->load->model('mdl_product_parts');
        
        $this->mdl_product_parts->type = "raw_material";
        $this->mdl_product_parts->id_of_selected_type = $_POST['raw_materials_id'];
        $this->mdl_product_parts->price = $_POST['raw_materials_unit_price'];
        
        $this->mdl_product_parts->updateNewPrices();
        
        $ids = $this->mdl_product_parts->get();
        
        foreach($ids as $row)
        {
            $this->load->model("mdl_product_parts"); //Load product parts model
            $this->mdl_product_parts->product_id = $row->product_id; //set the product ID so we know what product parts to fetch    
            $this->load->model("mdl_products");
            $this->mdl_products->product_id = $row->product_id;
            $percentageID = 0;
            //find percentage ID
            $result = $this->mdl_products->get();
            foreach($result as $r)
            {
                $percentageID = $r->product_percentage_id;
            }
        
            //Find Percentage
            $this->load->model("mdl_percentage");
            $this->mdl_percentage->percentage_id = $percentageID; //Set percentage ID to what was set on the edit products page
            $percentage = 0;
            
            $result = $this->mdl_percentage->get();
            foreach($result as $row)
            {
                $percentage = $row->percentage_value; //Set the percentage Varible to the percetnage value so we know how much markup.
            }
        
            $result = $this->mdl_product_parts->get();
            print_r($result);
            $total = 0;
            $laborHours = 0;
            $laborCost = 0;
            $materialCost = 0;
            $markup = $percentage;
            foreach($result as $row)
            {
                
                $temp = $row->price * $row->qty_of_selected_type;
                $total += $temp;
                
                //work out labor hours and cost
                if($row->type == "labor")
                {
                    $laborHours += $row->qty_of_selected_type;
                    $laborCost += ($row->qty_of_selected_type * $row->price);
                }
                
                if($row->type == "raw_material")
                {
                    $materialCost += ($row->qty_of_selected_type * $row->price);
                }
                
            }
            
            $sellingPrice = $total * $markup / 100;
            $sellingPrice += $total;
            
            
        
        $this->mdl_products->manual = "0"; //Manual is false becuase percentage method has been used
        $this->mdl_products->product_material_cost = $materialCost;
        $this->mdl_products->product_labor_cost = $laborCost;
        $this->mdl_products->product_labor_time = $laborHours;
        $this->mdl_products->product_selling_price = $sellingPrice;
        
        $this->mdl_products->product_percentage_id = $percentageID;


        $this->mdl_products->updateCalc();
        
        }


Messages In This Thread
Models Remember Vars? - by El Forum - 11-27-2008, 12:48 PM
Models Remember Vars? - by El Forum - 11-27-2008, 01:46 PM
Models Remember Vars? - by El Forum - 11-28-2008, 03:49 AM
Models Remember Vars? - by El Forum - 11-28-2008, 04:05 AM
Models Remember Vars? - by El Forum - 11-28-2008, 04:25 AM
Models Remember Vars? - by El Forum - 11-28-2008, 04:30 AM
Models Remember Vars? - by El Forum - 11-28-2008, 04:53 AM
Models Remember Vars? - by El Forum - 11-28-2008, 05:04 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.