Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function testCondition(Request $request)
- {
- $mains = WorkDescriptionMain::with([
- 'work_description',
- 'work_description.costs' => function ($q) {
- $q->where('worker_id', 4);
- },
- ])
- ->find(35);
- $want = 7; //จำนวนที่ต้องการ
- $sum = 0;
- $arrTest = [];
- foreach ($mains->work_description as $value) { //loop งาน
- foreach ($value->costs as $item) { //loop ราคา
- // $firstValue = $item['condition_value'];
- // $firstLabor = $item['labor_cost'];
- $arrTest[] = $item['labor_cost']; //เก็บค่าแรงใส่ใน array
- if ($item['case'] == 0) { //กรณีที่ 1
- echo $item['labor_cost'] * $want;
- } elseif ($item['case'] == 1) { //กรณีที่ 2
- if ($item['condition'] == "less_than_or_equal_to") {
- if ($want <= $item['condition_value']) {
- echo $sum = $item['labor_cost'] . "\n";
- }
- }
- if ($item['condition'] == "greater_than_or_equal_to") {
- if ($want >= $item['condition_value']) {
- echo $sum = $want * $item['labor_cost'] . "\n";
- }
- }
- } elseif ($item['case'] == 2) { //กรณีที่ 3
- if ($item['condition'] == "less_equal_to") {
- //
- if ($want <= $item['condition_value']) {
- echo $sum = $item['labor_cost'] . "\n";
- }
- }
- if ($item['condition'] == "greater_equal_to") {
- $difference = ($want - 7); //หาส่วนต่าง
- if ($want >= $item['condition_value']) {
- $sum = ($difference * $item['labor_cost']) + $arrTest[0]; //$arrTest[0] ตือราคาแรก
- echo $sum . "\n";
- }
- }
- } //end if main
- } //end foreach
- } //end foreach $mains
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement