Advertisement
maprangsoft

คำนวนราคา BSO แบบใหม่

Mar 4th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.38 KB | None | 0 0
  1.  public function testCondition(Request $request)
  2.     {
  3.      
  4.         $mains = WorkDescriptionMain::with([
  5.             'work_description',
  6.             'work_description.costs' => function ($q) {
  7.                 $q->where('worker_id', 4);
  8.             },
  9.         ])
  10.             ->find(35);
  11.  
  12.         $want = 7; //จำนวนที่ต้องการ
  13.         $sum = 0;
  14.         $arrTest = [];
  15.  
  16.         foreach ($mains->work_description as $value) { //loop งาน
  17.             foreach ($value->costs as $item) { //loop ราคา
  18.  
  19.                     // $firstValue = $item['condition_value'];
  20.                     // $firstLabor = $item['labor_cost'];
  21.                 $arrTest[] = $item['labor_cost']; //เก็บค่าแรงใส่ใน array
  22.  
  23.                 if ($item['case'] == 0) { //กรณีที่ 1
  24.  
  25.                     echo $item['labor_cost'] * $want;
  26.  
  27.                 } elseif ($item['case'] == 1) { //กรณีที่ 2
  28.  
  29.                     if ($item['condition'] == "less_than_or_equal_to") {
  30.                         if ($want <= $item['condition_value']) {
  31.                             echo $sum = $item['labor_cost'] . "\n";
  32.                         }
  33.                     }
  34.  
  35.                     if ($item['condition'] == "greater_than_or_equal_to") {
  36.                         if ($want >= $item['condition_value']) {
  37.                             echo $sum = $want * $item['labor_cost'] . "\n";
  38.                         }
  39.                     }
  40.  
  41.                 } elseif ($item['case'] == 2) { //กรณีที่ 3
  42.  
  43.                     if ($item['condition'] == "less_equal_to") {
  44.  
  45.                       //
  46.  
  47.                         if ($want <= $item['condition_value']) {
  48.                             echo $sum = $item['labor_cost'] . "\n";
  49.                         }
  50.  
  51.                     }
  52.  
  53.                     if ($item['condition'] == "greater_equal_to") {
  54.                         $difference = ($want - 7); //หาส่วนต่าง
  55.  
  56.                         if ($want >= $item['condition_value']) {
  57.                             $sum = ($difference * $item['labor_cost']) + $arrTest[0]; //$arrTest[0] ตือราคาแรก
  58.                             echo $sum . "\n";
  59.                         }
  60.                     }
  61.  
  62.                 } //end if main
  63.  
  64.             } //end foreach
  65.         } //end foreach $mains
  66.  
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement