Advertisement
maprangsoft

คำนวนราคาใบเสนอราคา ไฟฟ้า

Feb 29th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.37 KB | None | 0 0
  1. // function createCondition($want, $condition = [])
  2. // {
  3. //      foreach($condition as $con){
  4.      
  5. //       echo $a =  $want.$con."\n";
  6.      
  7. //       // if(){
  8.      
  9. //     }
  10. // }
  11.  
  12.  
  13. $array = [
  14. [
  15.     "id" =>  1,
  16.   "name" => "กระเบื้องธรรมดา ปูธรรมดา A",
  17.   "case" => 0,
  18.   "condition" => "less_than_or_equal_to",
  19.   "condition_value" => 10,
  20.   "labor" => 5400
  21. ],
  22.   [
  23.     "id" =>  2,
  24.   "name" => "กระเบื้องธรรมดา ปูธรรมดา A",
  25.      "case" => 0,
  26.       "condition" => "greater_than_or_equal_to",
  27.   "condition_value" => 11,
  28.   "labor" => 350
  29. ],
  30.     [
  31.     "id" =>  3,
  32.   "name" => "กระเบื้องธรรมดา ปูธรรมดา A",
  33.        "case" => 0,
  34.         "condition" => "greater_than_or_equal_to",
  35.   "condition_value" => 100,
  36.   "labor" => 320
  37. ],
  38.   [
  39.     "id" =>  4,
  40.   "name" => "งานเดินเมนระบบไฟฟ้า A",
  41.        "case" => 1,
  42.         "condition" => "less_than_or_equal_to",
  43.   "condition_value" => 7,
  44.   "labor" => 1450
  45.   ],
  46.     [
  47.     "id" =>  5,
  48.   "name" => "งานเดินเมนระบบไฟฟ้า A",
  49.        "case" => 1,
  50.         "condition" => "greater_than_or_equal_to",
  51.   "condition_value" => 8,
  52.   "labor" => 70
  53.   ],
  54.  
  55.  
  56. ];
  57.  
  58.  
  59. // dd($array);
  60. $want = 11;
  61. $sum = 0;
  62.  
  63. foreach($array as $value){
  64.  
  65.   if($value['case'] == 0){ //กรณีที่ 1
  66.  
  67.       if($value['condition'] == "less_than_or_equal_to"){
  68.     if($want <= $value['condition_value']){
  69.       echo $sum =  $value['labor']."\n";
  70.     }
  71.   }
  72.  
  73.   if($value['condition'] == "greater_than_or_equal_to"){
  74.     if($want >= $value['condition_value']){
  75.        echo $sum = $want * $value['labor']."\n";
  76.     }
  77.   }
  78.    
  79.   }else{ //กรณีที่ 2
  80.  
  81.    
  82.   if($value['condition'] == "less_than_or_equal_to"){
  83.  
  84.     // $firstValue = $value['condition_value'];
  85.     // $firstLabor = $value['labor'];
  86.  
  87.     if($want <= $value['condition_value']){
  88.        echo $sum =  $value['labor']."\n";
  89.     }
  90.    
  91.   }
  92.    
  93.     if($value['condition'] == "greater_than_or_equal_to"){
  94.     $difference =  ($want - 7); //หาส่วนต่าง
  95.    
  96.     if($want >= $value['condition_value']){
  97.       $sum = ($difference * $value['labor']) + 1450;
  98.       echo $sum."\n";
  99.     }
  100.   }
  101.  
  102.    
  103.    
  104.   }
  105.  
  106.  
  107.  
  108. } //end foreach
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement