public function target() { $product = 1; $territory = 1; $productTarget = ProductTarget::select('id', 'quantity')->where('product_id', $product)->where('year', 2015)->first(); $areaTarget = AreaTarget::select('id', 'percent', 'months_target')->where('product_target_id', $productTarget['id'])->first(); $areaUnits = $areaTarget['percent'] * $productTarget['quantity']; $territoryTarget = TerritoryTarget::select('id', 'percent', 'months_target')->where('area_target_id', $areaTarget['id'])->where('territory_id', $territory)->first(); $territoryUnits = $areaUnits * $territoryTarget['percent']; $target['jan'] = $territoryUnits * json_decode($territoryTarget['months_target']->jan); $target['feb'] = $territoryUnits * json_decode($territoryTarget['months_target']->feb); $target['mar'] = $territoryUnits * json_decode($territoryTarget['months_target']->mar); $target['apr'] = $territoryUnits * json_decode($territoryTarget['months_target']->apr); $target['may'] = $territoryUnits * json_decode($territoryTarget['months_target']->may); $target['jun'] = $territoryUnits * json_decode($territoryTarget['months_target']->jun); $target['jul'] = $territoryUnits * json_decode($territoryTarget['months_target']->jul); $target['aug'] = $territoryUnits * json_decode($territoryTarget['months_target']->aug); $target['sep'] = $territoryUnits * json_decode($territoryTarget['months_target']->sep); $target['oct'] = $territoryUnits * json_decode($territoryTarget['months_target']->oct); $target['nov'] = $territoryUnits * json_decode($territoryTarget['months_target']->nov); $target['dec'] = $territoryUnits * json_decode($territoryTarget['months_target']->dec); return $target; }
public static function target($current_month, $product, $territory) { $current_month = explode('-', $current_month); $year = 2016; $month = $current_month[0]; $target = []; $productTarget = ProductTarget::select('id', 'quantity')->where('product_id', $product)->where('year', $year)->first(); if (isset($productTarget)) { $areaTarget = AreaTarget::select('id', 'percent', 'months_target')->where('product_target_id', $productTarget['id'])->first(); $areaUnits = $areaTarget['percent'] * $productTarget['quantity']; if (isset($areaTarget)) { $territoryTarget = TerritoryTarget::select('id', 'percent', 'months_target')->where('area_target_id', $areaTarget['id'])->where('territory_id', $territory)->first(); } $territoryUnits = $areaUnits * $territoryTarget['percent']; if ($territoryTarget) { $target['Jan'] = $territoryUnits * json_decode($territoryTarget['months_target']->jan); $target['Feb'] = $territoryUnits * json_decode($territoryTarget['months_target']->feb); $target['Mar'] = $territoryUnits * json_decode($territoryTarget['months_target']->mar); $target['Apr'] = $territoryUnits * json_decode($territoryTarget['months_target']->apr); $target['May'] = $territoryUnits * json_decode($territoryTarget['months_target']->may); $target['Jun'] = $territoryUnits * json_decode($territoryTarget['months_target']->jun); $target['Jul'] = $territoryUnits * json_decode($territoryTarget['months_target']->jul); $target['Aug'] = $territoryUnits * json_decode($territoryTarget['months_target']->aug); $target['Sep'] = $territoryUnits * json_decode($territoryTarget['months_target']->sep); $target['Oct'] = $territoryUnits * json_decode($territoryTarget['months_target']->oct); $target['Nov'] = $territoryUnits * json_decode($territoryTarget['months_target']->nov); $target['Dec'] = $territoryUnits * json_decode($territoryTarget['months_target']->dec); } return $target[$month]; } }