{
  "info": "",
  "field": {
      "update": [
        ["w_lrC_KENTAT"]
      ],
      "w_work_id": [
        ["_code_CLEAN", ["w_work_id"]],
        [
          [
            "if", ["w_work_id", "<>", ["w_work_position_num_id"]],
            [
              ["w_work_position_num_id", "=", ["w_work_id"]],
              [
                "if", ["_fi_RecNew", "=", "true"],
                [
                  ["pr_work_position_number", "=", ["w_work_position_num_id"]]
                ]
              ]
            ]
          ]
        ]
      ],
      "w_work_position_num_id": [
        ["_code_CLEAN", ["w_work_position_num_id"]],
        [
          "if", ["w_work_id", "<>", ["w_work_position_num_id"]],
          [
            ["w_work_id", "=", ["w_work_position_num_id"]]
          ]
        ],
        [
          "if", ["_fi_RecNew", "=", "true"],
          [
            ["pr_work_position_num_id", "=", ["w_work_position_num_id"]],
            [
              "if", [["_rec_NewRecord", ["pr"]], "=", "true"],
              [
                "if", ["g.w_fTPo_Laad"],
                [
                  ["pr_quality", "=", ["pr_work_position_num_id"]],
                  ["xapp_TblRun", ["pr_quality", "pr", "noevent"]]
                ],
                "elseif", ["g.w_fPiir_laa"],
                [
                  ["pr_quality", "=", ["w_drawing_number"]],
                  ["xapp_TblRun", ["pr_quality", "pr", "noevent"]]
                ]
              ]
            ]
          ]
        ]
      ],
      "w_state": [],
      "w_level": [],
      "w_name": [
        [
          "if", ["_fi_RecNew", "=", "true"],
          [
            ["pr_name", "=", "w_name"]
          ],
          "else",
          [
            ["CONFIRM", ["concat", [["_lang_Current", ["Do_you_want_to_copy_work_name_to_product_name?"]], "\n", "pr_name", " ", "w_name"]]],
            [
              "if", ["OK", "=", "1"],
              [
                ["pr_name", "=", "w_name"]
              ]
            ]
          ]
        ]
      ],
      "w_creation_date": [],
      "w_modification_date": [],
      "w_modifier_id": [],
      "w_info": [],
      "w_calculation_lot": [
        ["w_scCALCULATION_LOT"]
      ],
      "w_part_upper_level": [],
      "w_sales_price_locked": [
        [
          "if", ["_fld_ValueBoolean", ["w_sales_price_locked", "=", "true"]],
          [
            ["_w_lEnterable", "=", "false"]
          ],
          "else",
          [
            ["_w_lEnterable", "=", "true"]
          ]
        ],
        ["_var_ENTERABLE_SET", ["_w_lEnterable", "pr_sales_price_unit", "w_rLKatePro", "w_rSMHkpl_a", "w_rSMHyht", "w_rSMHyht_a"]]
      ],
      "w_remaining_amount": [],
      "w_produced_amount": [],
      "w_est_material_cost_unit": [],
      "w_est_mat_sales_price_unit": [],
      "w_est_setup_time_unit": [],
      "w_est_work_time_unit": [],
      "w_est_salary_unit": [],
      "w_est_work_cost_unit": [],
      "w_est_work_sales_price_unit": [],
      "w_est_subc_cost_unit": [],
      "w_est_subc_sales_price_unit": [],
      "w_act_material_cost_total": [],
      "w_act_setup_time_total": [],
      "w_act_work_time_total": [],
      "w_act_salary_total": [],
      "w_act_work_cost_total": [],
      "w_act_subc_cost_total": [],
      "w_conf_mat_sales_price_unit": [
        ["w_C_MUUTUJAT"],
        ["w_lrC_MUUTTUJAT"]
      ],
      "w_conf_work_sales_price_unit": [
        ["w_C_MUUTUJAT"],
        ["w_ltC_MUUTTUJAT"]
      ],
      "w_conf_subc_sales_price_unit": [
        ["w_C_MUUTUJAT"],
        ["w_ltC_MUUTTUJAT"]
      ],
      "w_position": [],
      "w_company_id": [
        ["pr_customer_id", "=", ["w_company_id"]]
      ],
      "w_act_mat_sales_price_total": [],
      "w_act_work_sales_price_total":[],
      "w_act_subc_sales_price_total": [],
      "w_production_amount": [],
      "w_waiting_for_delivery": [],
      "w_delivered_amount": [],
      "w_deliveries": [],
      "w_drawing_number": [
        ["w_scPIIRUSTUSNU"]
      ],
      "w_social_cost_multiplier": [],
      "w_vat_percentage": [],
      "w_part_main_leve": [],
      "w_firm_id": [],
      "w_product_id": [],
      "w_transfer_id": []
  },
  "function": {
    "w_lrC_KENTAT": [
      ["w_est_material_cost_unit", "=", ["Sum", ["wme_cost_price_unit"]]],
      ["w_est_mat_sales_price_unit", "=", ["Sum", ["wme_sales_price_unit"]]],
      ["w_pr_PRICES_UPDATE"],
      ["_rec__REC_TO_INPUT_VAR", ["pr_tbl"]],
      ["w_lrC_MUUTTUJAT"]
    ],
    "w_pr_PRICES_UPDATE": [
      ["w_pr__SUBCONTRACT_PRICE_UPDATE"],
      ["pr_cost_price_unit", "=", ["w_est_material_cost_unit", "+", "w_est_work_cost_unit", "+", "w_est_subc_cost_unit"]],
      [
        "if", ["pr_purchase_price_unit", ">", "0"],
        [
          ["pr_purchase_multiplier", "=", ["pr_cost_price_unit", "/", ["pr_purchase_price_unit"]]]
        ]
      ],
      ["pr_calculated_sales_pr_unit", "=", ["w_est_mat_sales_price_unit", "+", "w_est_work_sales_price_unit", "+", "w_est_subc_sales_price_unit"]],
      [
        "if", ["pr_cost_price_unit", ">", "0"],
        [
          ["pr_profit_multiplier", "=", ["pr_sales_price_unit", "/", "pr_cost_price_unit"]]
        ]
      ]
    ],
    "w_pr__SUBCONTRACT_PRICE_UPDATE": [
      ["COMPILER_w"],
      [
        "if", ["g.w_lPurchasePriceUpdate", "=", "true"],
        [
          [
            "if", [["_sel_RecsInSel", ["wpe_tbl"]], ">", "0"],
            [
              ["pr_purchase_price_unit", "=", ["Sum", ["wpe_subcont_purc_price_unit"]]]
            ],
            "else",
            [
              ["pr_pruchase_price_unit", "=", "0"]
            ]
          ],
          [
            "if", ["pr_pruchase_price_unit", ">", "0"],
            [
              ["pr_purchase_multiplier", "=", ["pr_cost_price_unit", "/", "pr_purchase_price_unit"]]
            ]
          ]
        ]
      ]
    ],
    "w_scCALCULATION_LOT": [
      ["_fii_ACTIVATE", ["wpe_tbl"]],
      [
        "if", ["_fii_CurrentTbl", "<>", ["wpe_tbl"]],
        [
          ["TRACE"]
        ],
        "else",
        [
          ["_w_lSelectedRecordNumber", "=", ["_sel__SelectedRecNum", ["wpe_tbl"]]],
          ["_w_lSelSize", "=", ["_sel_RecsInSel", ["wpe_tbl"]]],
          [
            "if", ["_w_lSelSize", ">", "0"],
            [
              ["wpe__CALCULATION_AMOUNT_UPDATE, ---- ??, ei ole w_ -alkuinen", ["true"]],
              [
                "if", ["_w_lSelectedRecordNumber", ">", "0"],
                [
                  ["_rec_SELECTED_GOTO", ["wpe_tbl", "_w_lSelectedRecordNumber"]]
                ]
              ],
              ["_w_pFld", "=", ["_fld_NumToPtr", ["w_calculation_lot"]]],
              ["GOTO_OBJECT", ["_w_pFld"]]
            ]
          ]
        ]
      ],
      ["w_lrC_MUUTTUJAT"],
      ["w_ltC_MUUTTUJAT"]
    ],
    "w_C_MUUTUJAT": [
      ["w_rLOKkpl", "=", ["w_est_material_cost_unit", "+", "w_est_work_cost_unit", "+", "w_est_subc_cost_unit"]],
      ["w_rLOKyht", "=", ["w_rLOKkpl", "*", "w_calculation_lot"]],
      ["w_rLMHkpl", "=", ["w_est_mat_sales_price_unit", "+", "w_est_work_sales_price_unit", "+", "w_est_subc_sales_price_unit"]],
      ["w_lmhyht", "=", ["w_rLMHkpl", "*", "w_calculation_lot"]],
      [
        "if", [["_el_Tbl", "=", ["wpe"]], "and", ["_fi_InFullpage", "=", "true"]],
        [
          ["IDLE"]
        ],
        "else",
        [
          ["w_sYksikko", "=", ["pr_unit"]],
          ["w_rTuMH", "=", ["pr_sales_price_unit"]],
          ["w_rTuMHyht", "=", ["w_rTuMH", "*", "w_calculation_lot"]],
          ["w_rSMHyht", "=", ["pr_sales_price_unit", "*", "w_calculation_lot"]],
          ["w_rSMHkpl_a", "=", ["Round", ["aaC_MK_LvvMK", ["pr_sales_price_unit", "g.grAlv", "g.pr_pyorahin"]]]],
          ["w_rSMHyht_a", "=", ["w_rSMHkpl_a", "*", "w_calculation_lot"]],
          [
            "if", ["w_rSMHyht", "<>", "0"],
            [
              ["w_rLKatePro", "=", ["Round", [[[["w_rSMHyht", "-", "w_rLOKyht"], "/", "w_rSMHyht"], "*", "100"], "5"]]]
            ],
            "else",
            [
              ["w_rLKatePro", "=", "0"]
            ]
          ],
          [
            "if", ["w_rLKatePro", "<=", "0"],
            [
              ["_var_COLOR_SET", ["w_rLKatePro", "Red", "1"]]
            ],
            "else",
            [
              ["_var_COLOR_SET", ["w_rLKatePro", "1", "1"]]
            ]
          ],
          ["w_margin_unit", "=", ["w_rTuMH", "-", "w_rLOKkpl"]],
          ["w_margin_total", "=", ["w_rTuMHyht", "-", "w_rLOKyht"]],
          [
            "if", ["w_margin_total", "<", 0],
            [
              ["_var_COLOR_SET", ["w_margin_unit", "Red", "1"]],
              ["_var_COLOR_SET", ["w_margin_total", "Red", "1"]]
            ],
            "else",
            [
              ["_var_COLOR_SET", ["w_margin_unit", "1", "1"]],
              ["_var_COLOR_SET", ["w_margin_total", "1", "1"]]
            ]
          ],
          [
            "if", [["_fld_ValueLong", ["pr_production_control_type"]], "=", ["g.pr_stlim_lProdCtrlType_Stock"]],
            ["_w_tAbbreviation", "=", ["_lang_Current", ["Abbreviation/Stock"]]],
            [
              "if", ["_w_tAbbreviation", "=", ["Abbreviation/Stock"]],
              [
                ["_w_tAbbreviation", "=", ["String", ["g.pr_stlim_lProdCtrlType_Stock"]]]
              ]
            ],
            "else",
            [
              ["_w_tAbbreviation", "=", ["_lang_Current", ["Abbreviation/Stock"]]],
              ["_w_tAbbreviation", "=", ["Abbreviation/Stock"]],
              [
                ["_w_tAbbreviation", "=", ["String", ["g.pr_stlim_lProdCtrlType_Order"]]]
              ]
            ]
          ],
          ["w_tProductionControlType", "=", ["_w_tAbbreviation"]]
        ]
      ]
    ],
    "w_lrC_MUUTTUJAT": [
      ["w_lrrOKyht", "=", ["w_est_material_cost_unit", "*", "w_calculation_lot"]],
      ["w_lrrMHyht", "=", ["w_est_mat_sales_price_unit", "*", "w_calculation_lot"]],
      ["w_lrrSMHyht", "=", ["w_conf_mat_sales_price_unit", "*", "w_calculation_lot"]],
      ["w_C_MUUTUJAT"]
    ],
    "w_ltC_MUUTTUJAT": [
      ["w_ltrTyot", "=", ["w_est_setup_time_unit", "+", "w_est_work_time_unit"]],
      ["w_ltr_tyotyh", "=", ["w_ltrTyot", "*", "w_calculation_lot"]],
      ["w_ltrAsayht", "=", ["w_est_setup_time_unit", "*", "w_calculation_lot"]],
      ["w_ltrTyoayh", "=", ["w_est_work_time_unit", "*", ["w_calculation_lot"]]],
      ["w_ltrOKyht", "=", ["w_est_work_cost_unit", "*", "w_calculation_lot"]],
      ["w_ltrMHyht", "=", ["w_est_work_sales_price_unit", "*", "w_calculation_lot"]],
      ["w_ltrAlihOK", "=", ["w_est_subc_cost_unit", "*", "w_calculation_lot"]],
      ["w_ltrAlihMH", "=", ["w_est_subc_sales_price_unit", "*", "w_calculation_lot"]],
      ["w_C_MUUTUJAT"]
    ],
    "w_scPIIRUSTUSNU": [
      [
        "if", ["rbtuTuoteko", "=", "1"],
        [
          [
            "if", [["_rec_NewRecord", ["pr_tbl"]], "=", "true"],
            [
              [
                "if", ["pr_supplier_material_code", "=", ["pr_product_code"]],
                [
                  ["pr_supplier_material_code", "=", ["w_drawing_number"]]
                ]
              ],
              ["pr_product_code", "=", ["w_drawing_number"]],
              ["pr_product_id", "=", ["pr_product_code"]],
              ["pr_TEE_LYHENNE ---- ??, ei ole w_ -alkuinen"]
            ]
          ]
        ],
        "else",
        [
          [
            "if", ["pr_supplier_material_code", "=", ["pr_product_code"]],
            [
              ["pr_supplier_material_code", "=", ["w_drawing_number"]]
            ]
          ],
          ["pr_product_code", "=", ["w_drawing_number"]]
        ]
      ],
      [
        "if", [["g.w_fPiir_laa"], "and", [["_rec_NewRecord", ["pr_tbl"]], "=", "true"]],
        [
          ["pr_quality", "=", ["w_drawing_number"]],
          [
            "if", ["rbtuTuoteko", "=", "0"],
            [
              ["pr_TEE_LYHENNE  ---- ??, ei ole w_ -alkuinen"]
            ]
          ]
        ]
      ],
      [
        "if", ["pr_supplier_material_code", "=", ""],
        [
          ["pr_supplier_material_code", "=", ["pr_product_code"]]
        ]
      ],
      [
        "if", [["g.pr_lDrawingNumberFieldNum", "<>", "0"], "and", ["w_drawing_number", "<>", ""], "and", ["g.pr_lDrawingNumberFieldNum", "<>", ["pr_product_id"]], "and", ["g.pr_lDrawingNumberFieldNum", "<>", ["pr_work_position_num_id"]]],
        [
          ["_fld_VALUE_STR_SET", ["set", "g.pr_lDrawingNumberFieldNum", "_w_tDrawingNumber"]]
        ]
      ]
    ]
  }
}
