예제 #1
0
 /**
  * Function that calculates the percentage of order completion.
  */
 public function percentageCompleted()
 {
     // Get the Order Breakdown.
     $toProduction = $this->breakdown;
     // Extract the information we need to calculate percentage of completion.
     $totalProduction = array();
     $totalToProduce = 0;
     $totalProduced = 0;
     foreach ($toProduction as $production) {
         $totalProduction[$production->Code] = $production->Quantity;
     }
     // Get the total stages to produce each product and multiply it by the totalProduction.
     foreach ($totalProduction as $code => $amount) {
         $expenses = ProductionExpense::where('Code', '=', $code)->get();
         $maxStage = 0;
         foreach ($expenses as $expense) {
             $maxStage = $maxStage < $expense->Stage ? $expense->Stage : $maxStage;
         }
         $totalToProduce = $totalProduction[$code] * $maxStage;
     }
     // Get the existing production of order.
     $allProduced = $this->production;
     foreach ($allProduced as $produced) {
         $totalProduced += $produced->Stage;
     }
     // Calculate precentage of completion and return result.
     $percentageCompleted = $totalProduced / $totalToProduce * 100;
     return $percentageCompleted;
 }
예제 #2
0
 /**
  * Function that gets the max stage of current OrderBreakdown.
  */
 public function maxStage()
 {
     // Get all the expenses.
     $expenses = ProductionExpense::where('Code', '=', $this->Code)->get();
     // Loop through all expenses and add them to each array.
     $maxStage = 0;
     foreach ($expenses as $expense) {
         $maxStage = $expense->Stage;
     }
     return $maxStage;
 }
예제 #3
0
 /**
  * Function to define current expense of production.
  */
 public function currentExpense()
 {
     return ProductionExpense::where('Code', '=', $this->Code)->where('Stage', '=', $this->Stage)->first();
 }