{
  "info": "",
  "field": {
    "sigle_click": [
      ["IDLE"],
      ["wo_tPrevState", "=", ["wo_state"]],
      ["wo_lPrevRow", "=", ["wo_row_number"]],
      ["pr_nc__PRODUCT_STATE", ["w_product_id", "wo_remaining_amount", "wo_delivery_date"]]
    ],
    "wo": [
      ["_wo_dCurrent", "=", ["_date_Current", ["true"]]],
      ["w_RELATE_TUOTE"],
      [
        "if", ["g.wo_lCopyWorkInfoToWorkOrder", "=", true],
        [
          ["wo_info", "=", ["wo_info"]]
        ]
      ],
      ["wo_work_position_num_id", "=", ["w_work_position_num_id"]],
      ["wo_drawing_number", "=", "w_drawing_number"],
      ["wo_start_date", "=", ["_wo_dCurrent"]],
      ["wo_start_week", "=", ["_date_ToWeek", ["wo_start_date"]]],
      ["wo_est_finish_week", "=", ["wo_start_week"]],
      ["wo_start_time", "=", ["g.vahAloitusa"]],
      ["wo_state", "=", ["g.vasTila"]],
      ["wo_row_number", "=", ["Max", ["wo_row_number", "+", "1"]]],
      ["wo_production_lot", "=", ["vaC_Era", ["wo_work_position_num_id", "wo_row_number"]]],
      ["wo_firm_id", "=", ["w_firm_id"]],
      ["wo_est_finish_time", "=", ["g.wo_hDefaultDeliveryClockTime"]],
      [
        "if", ["_fii_RecNew", "=", "true"],
        [
          [
            "if", [["w__CallingPrs_so", ["get"]], "=", "true"],
            [
              ["wo_delivery_date", "=", ["sor__DeliveryDate"]],
              ["wo_started_amount", "=", ["sor_ordered_amount"]],
              [
                "if", ["wo_started_amount", "<", ["pr_min_purchase_amount_unit"]],
                [
                  ["wo_started_amount", "=", ["pr_min_purchase_amount_unit"]]
                ]
              ],
              ["wo_sales_order_id", "=", ["sor_sales_order_id"]],
              ["wo_sales_order_row_id", "=", ["sor_row_number"]],
              [
                "if", ["sor_pricing_state", "<>", "1"],
                [
                  ["wo_sales_price_unit", "=", ["wo_GetAHinta", ["sor_price_unit"]]],
                  ["wo_sales_price_unit", "=", ["cur_C_Currency", ["true", "1", "1", "so_currency_id", "wo_sales_price_unit", "_wo_tDefaultCurrency"]]]
                ]
              ],
              ["wo_pricing_state", "=", ["sor_price_unit"]],
              [
                "if", ["pr_production_control_type", "<>", ["g.pr_stlim_lProdCtrlType_Stock"]],
                [
                  ["wo_company_id", "=", ["so_company_id"]],
                  [
                    "if", ["g.wo_lCopySorSerialNumToWorkOrder", "=", "true"],
                    [
                      ["_txt", "=", ["_fld_ValueStr", ["sor_serial_number"]]],
                      ["_fld_VALUE_STR_SET", ["set", "wo_serial_number", "_txt"]]
                    ]
                  ],
                  ["_date", "=", ["wo_delivery_date"]],
                  ["_fld_VALUE", ["set", "wo_critical_date", "_date"]],
                  ["_fld_VALUE", ["set", "wo_critical_date_delayed", "_date"]],
                  ["_fld_VALUE", ["set", "wo_critical_date_real", "_date"]],
                  ["_lnk__CREATE", ["wo", "currentrecord", "sor", "currentrecord"]]
                ],
                "else",
                [
                  ["wo_company_id", "=", ["w_company_id"]]
                ]
              ],
              ["w__CallingPrs_so", ["delete"]]
            ],
            "else",
            [
              [
                "if", ["pr_min_purchase_amount_unit", ">", "0"],
                [
                  ["wo_started_amount", "=", ["pr_min_purchase_amount_unit"]]
                ],
                "else",
                [
                  ["wo_started_amount", "=", ["w_calculation_lot"]]
                ]
              ],
              ["wo_company_id", "=", ["w_company_id"]],
              ["wo_sales_price_unit", "=", ["wo_GetAHinta", ["pr_sales_price_unit"]]]
            ]
          ],
          [
            "if", [["_fld_ValueLong", ["pr_production_control_type"]], "=", ["g.pr_stlim_lProdCtrlType_Stock"]],
            [
              ["pr_nc_PRODUCT_STATE_VALUES_GET", ["w_product_id", "1", "w_rComing", "w_rReserved", "w_rFree", "w_dDeliveryDate", "w_dCriticalDate"]],
              ["wo_delivery_date", "=", ["w_dCriticalDate"]],
              ["_wo_rDifference", "=", ["w_rFree", "-", ["_fld_ValueReal", ["pr_action_limit_unit"]]]],
              [
                "if", ["_wo_rDifference", ">", "0"],
                [
                  ["wo_started_amount", "=", "0"]
                ],
                "elseif", [["Abs", ["_wo_rDifference"]], "<", ["_fld_ValueReal", ["pr_min_purchase_amount_unit"]]],
                [
                  ["wo_started_amount", "=", ["pr_min_purchase_amount_unit"]]
                ],
                "else",
                [
                  ["wo_started_amount", "=", ["Abs", ["_wo_rDifference"]]]
                ]
              ]
            ],
            [
              "if", ["wo_started_amount", "<=", "0"],
              [
                ["wo_started_amount", "=", ["pr_min_purchase_amount_unit"]]
              ]
            ],
            [
              "if", ["g", ["wo_add_lUseMaxProductionAmount", "=", "true"]],
              [
                [
                  "if", [["pr_max_production_amount", ">", "0"], "and", ["wo_started_amount", ">", ["pr_max_production_amount"]]],
                  [
                    ["wo_started_amount", "=", "pr_max_production_amount"]
                  ]
                ]
              ]
            ],
            ["wo_sales_order_id", "=", ""],
            ["wo_sales_order_row_id", "=", "0"]
          ]
        ]
      ],
      ["wo_remaining_amount", "=", ["wo_started_amount"]],
      ["w_vaC_KENTAT"]
    ],
    "wo_work_position_num_id": [
      ["vascTYO_POS_NRO"]
    ],
    "wo_row_number": [
      ["wo_production_lot", "=", ["vaC_Era", ["wo_work_position_num_id", "wo_row_number"]]],
      ["_code_CLEAN", ["wo_production_lot"]]
    ],
    "wo_production_lot": [
      ["_code_CLEAN", ["wo_production_lot"]]
    ],
    "wo_start_week": [
      ["_week_FORMAT", ["wo_start_week"]],
      ["wo_start_date", "=", ["aaC_Week_Date", ["wo_start_week"]]],
      [
        "if", ["_fi_InFullpage", "=", "true"],
        [
          ["vascTYON_AL_VK"]
        ]
      ]
    ],
    "wo_start_date": [
      ["wo_start_week", "=", ["aaC_Date_Week", ["wo_start_date"]]],
      [
        "if", ["_fi_InFullpage", "=", "true"],
        [
          ["vascTYON_AL_PV"]
        ]
      ]
    ],
    "wo_started_amount": [
      ["vascALOITETTAVA"]
    ],
    "wo_act_finish_week": [
      ["_week_FORMAT", ["wo_act_finish_week"]],
      ["vascTYON_VAL_VK"]
    ],
    "wo_act_finish_date": [
      ["vascTYON_VAL_PV"]
    ],
    "wo_produced_amount": [
      ["vascVALMISTUNUT"]
    ],
    "wo_state": [
      ["wo_state", "=", ["_str__ToUpper", ["wo_state"]]],
      [
        "if", [["wo_tPrevState", "=", ["g.wo_state_stopped"]], "and", ["wo_lPrevRow", "=", ["wo_row_number"]], "and", ["wo_state", "<>", ["g.wo_state_stopped"]]],
        [
          ["wo_state", "=", ["wo_StoppedStateChange", ["wo_state"]]],
          ["_pop_FLD", ["On_Load", "wo_state", "0"]]
        ]
      ],
      ["wo_tPrevState", "=", ["wo_state"]],
      ["wo_lPrevRow", "=", ["wo_row_number"]],
      ["_wo_fConfirm", "=", "false"],
      ["wo_C_TILA", ["wo_production_lot", "_wo_fConfirm"]]
    ],
    "wo_company_id": [],
    "wo_work_order_id": [
      ["_code_CLEAN", ["wo_work_order_id"]]
    ],
    "wo_sales_order_id": [],
    "wo_purchase_order_id": [],
    "wo_info": [],
    "wo_print_date": [],
    "wo_delivery_date": [],
    "wo_start_time": [],
    "wo_partial_delivery_number": [],
    "wo_remaining_amount": [],
    "wo_type": [],
    "wo_stock_event_id": [],
    "wo_in_report": [],
    "wo_drawing_number": [],
    "wo_sales_price_unit": [
      ["wo_scPRICING_STATE"]
    ],
    "wo_finished_work_phase": [],
    "wo_firm_id": [],
    "wo_sales_order_row_id": [],
    "wo_est_finish_week": [
      ["_week_FORMAT", ["wo_est_finish_week"]],
      ["vascARV_VAL_VK"]
    ],
    "wo_est_finish_date": [
      ["vascARV_VAL_PV"]
    ],
    "wo_serial_number": [],
    "wo_transfer_info": [],
    "wo_material_act_arrival_date": [
      ["wo_scMATERIAL_ACT_ARRIVAL_DATE"]
    ],
    "wo_material_est_arrival_date": [
      ["wo_scMATERIAL_EST_ARRIVAL_DATE"],
      ["if", ["false"],
        [
          ["ret", "=", "false"]
        ]
      ]
    ],
    "wo_est_finish_time": [],
    "wo_record_id": [],
    "wo_creation_date": [],
    "wo_critical_date": [],
    "wo_failed_amount": [
      ["wo_remaining_amount", "=", ["wo_started_amount", "-", "wo_failed_amount"]]
    ],
    "wo_critical_date_delayed": [],
    "wo_critical_date_real": [],
    "wo_transfer_id": [],
    "wo_critical_start_date": [],
    "wo_critical_start_time": [],
    "wo_additional_data": [],
    "wo_project_id": [],
    "wo_critical_start_difference": [],
    "wo_est_finish_difference": [],
    "wo_change_id": [],
    "wo_creator_id": [],
    "wo_modifier_id": [],
    "wo_transfer_state": [],
    "wo_parent_production_lot": [],
    "wo_work_order_type": [],
    "wo_track_time_status": [],
    "wo_pricing_state": [
      ["wo_scPRICING_STATE"]
    ]
    },
  "function": {
    "w_RELATE_TUOTE": [
      [
        "if", ["pr_work_position_num_id", "<>", ["w_work_position_num_id"]],
        [
          ["_txt", "=", ["_w_tWork"]],
          ["_qry_Fld", ["0", "pr_work_position_num_id", "=", "_txt", "", "false"]]
        ]
      ]
    ],
    "w_vaC_KENTAT": [
      [
        "if", ["_el_Tbl", "=", ["w"]],
        [
          ["_real", "=", ["_sel_Sum", ["wo_remaining_amount"]]],
          ["_fld_VALUE_REAL_SET", ["set", "w_remaining_amount", "_real"]],
          ["_real", "=", ["_sel_Sum", ["wo_produced_amount"]]],
          ["_fld_VALUE_REAL_SET", ["set", "w_produced_amount", "_real"]],
          ["_long", "=", ["_sel_RecsInSel", ["wo"]]],
          ["_fld_VALUE_LONG_SET", ["set", "w_production_amount", "_long"]],
          ["_date", "=", "_date_Current", ["true"]],
          ["_fld_VALUE_DATE_SET", ["set", "w_modification_date", "_date"]],
          ["_txt", "=", ["_usr_CurrentUser"]],
          ["_fld_VALUE_STR_SET", ["set", "w_modifier_id", "_txt"]]
        ]
      ]
    ],
    "vascTYO_POS_NRO": [
      ["wo_company_id", "=", ["w_company_id"]],
      ["wo_started_amount", "=", ["w_calculation_lot"]],
      ["wo_start_date", "=", ["Current_date"]],
      ["wo_start_week", "=", ["aaC_Date_Week", ["wo_start_date"]]],
      ["wo_production_lot", "=", ["vaC_Era", ["wo_work_position_num_id", "wo_row_number"]]]
    ],
    "vascTYON_AL_VK": [
      ["wo_start_date", "=", [["aaC_Date_Week", ["wo_start_week"]], "-", "4"]],
      ["wo_act_finish_week", "=", ["wo_start_week"]]
    ],
    "wo_scPRICING_STATE": [
      [
        "if", [["wo_pricing_state", "=", "3"], "and", ["wo_sales_price_unit", "=", "0"]],
        [
          ["_err_CRY", [["_lang_Current", ["Sales_Price_may_not_be_zero"]], "false"]]
        ],
        "else",
        [
          ["_wo_lSorSelection", "=", ["wo__OpenSorFind", ["wo_production_lot", "w_product_id"]]],
          [
            "if", ["_wo_lSorSelection", ">", "0"],
            [
              ["_WRITE_STATE", ["sor", "true"]],
              ["_rec_LOCKED_WAIT", ["sor", "true"]],
              [
                "if", ["OK", "=", "1"],
                [
                  ["_fld_VALUE_LONG_SET", ["set", "sor_pricing_state", "wo_pricing_state"]],
                  [
                    "if", ["wo_pricing_state", "=", "3"],
                    [
                      ["_fld_VALUE_LONG_SET", ["set", "sor_price_unit", "wo_sales_price_unit"]],
                      ["xapp_TblRun", ["sor_price_unit", "sor", "noevent"]]
                    ],
                    ["_rec_SAVE", ["sor"]],
                    [
                      "if", ["wo_pricing_state", "=", "3"],
                      [
                        ["_sel_RELATE_ONE", ["so_sale_order_id", "sor_sales_order_id"]],
                        ["_rel__UP_CALCULATE_DO", ["so", "true", "true", "false", "false"]],
                        ["_rec_UNLOAD", ["so"]]
                      ]
                    ],
                    ["_rec_UNLOAD", ["sor"]]
                  ]
                ]
              ],
              ["_WRITE_STATE", ["sor", "previous"]]
            ]
          ]
        ]
      ]
    ],
    "vascARV_VAL_VK": [
      ["wo_est_finish_date", "=", ["aaC_Week_Date", ["wo_est_finish_week", "-", "4"]]],
      [
        "if", ["wo_delivery_date", "=", "00.00.0000"],
        [
          ["wo_delivery_date", "=", ["aaC_Week_Date", ["wo_est_finish_week"]]]
        ]
      ]
    ],
    "vascARV_VAL_PV": [
      ["wo_est_finish_week", "=", ["aaC_Date_Week", ["wo_est_finish_date"]]]
    ],
    "wo_scMATERIAL_ACT_ARRIVAL_DATE": [
      [
        "if", ["wo_material_act_arrival_date", "<>", "00.00.0000"],
        [
          ["_wo_tMessage", "=", ["concat", [["_lang_Current", ["Material_purchase_order_exists"]], ". ", "\n"]]],
          ["_wo_tMessage", "=", ["concat", ["_wo_tMessage", "+", ["_lang_Current", ["Receive_materials_via_purchase_order_receiving-action"]], "."]]],
          [
            "if", [["wo_MaterialDateSetAllow", ["wo_production_lot", "_wo_tMessage"]], "=", "false"],
            [
              ["_fld_VALUE_DATE_SET", ["set", "wo_material_act_arrival_date", "00.00.0000"]]
            ],
            "else",
            [
              [
                "if", [["_rec_NewRecord", ["wo_tbl"]], "=", "true"],
                [
                  ["_fld_VALUE_DATE_SET", ["set", ["wo_material_est_arrival_date", "wo_material_act_arrival_date"]]]
                ]
              ],
              ["_wo_tNewState", "=", ""],
              ["_wo_tWosNewState", "=", ""],
              [
                "if", ["wo_material_act_arrival_date", "=", "00.00.0000"],
                [
                  [
                    "if", ["wo_state", "=", ["g.wo_sState_Loaded"]],
                    [
                      ["_wo_tNewState", "=", ["g.wo_sState_Loaded"]],
                      ["_wo_tWosNewState", "=", ["g.wo_sState_NotLoaded"]]
                    ]
                  ],
                  ["_wo_rWosProducedAmount", "=", "0"],
                  ["_wo_rWosRemainingAmount", "=", ["_wo_rStartedAmount"]],
                  ["COMPILER_po"],
                  ["_txt", "=", ["_wos_tProductionLot"]],
                  ["_wo_lPorFound", "=", ["_qry_Fld", ["por_tbl", ["por_product_lot", "=", ["_txt"]], "*", "false"]]],
                  ["_txt", "=", ["g.po_tType_Material"]],
                  ["_wo_lPorFound", "=", ["_qry_Fld", ["por_tbl", ["por_type", "=", ["_txt"]], "&", "false"]]],
                  [
                    "if", ["_wo_lPorFound", ">", "0"],
                    [
                      ["_wo_tWosNewState", "=", ["g.wo_sState_Started"]]
                    ]
                  ],
                  ["_por_lWosFound", "=", ["wos__Select_Create", ["_wos_tProductionLot", "0", "false"]]],
                  [
                    "if", ["_por_lWosFound", ">", "0"],
                    [
                      [
                        "if", [["_fld_ValueStr", ["wos_work_load_group_id"]], "=", ["g.w_tRawMaterialLoadGroupId"]],
                        [
                          ["_tbl_WRITE_STATE", ["wos_tbl", "true"]],
                          ["_rec_LOCKED_WAIT", ["wos_tbl", "true"]],
                          [
                            "if", ["OK", "=", "1"],
                            [
                              ["_fld_VALUE_REAL_SET", ["set", "wos_produced_amount", "_wo_rWosProducedAmount"]],
                              ["_fld_VALUE_REAL_SET", ["set", "wos_remaining_amount", "_wo_rWosRemainingAmount"]],
                              [
                                "if", ["_wo_tWosNewState", "<>", ""],
                                [
                                  ["_fld_VALUE_STR_SET", ["set", "wos_work_phase_state", "_wo_tWosNewState"]]
                                ]
                              ],
                              ["_rec_SAVE", ["wos_tbl"]],
                              ["wos_STATE_CHANGE ---- ??, ei ole wo_ -alkuinen"],
                              ["wo__FAILED_AND_REMAINING_SET", [""]],
                              [
                                "if", ["g.wo_lPorChangeWoAmount", ">", "0"],
                                [
                                  ["_info_YesNoCancel", ["confirm", ["concat", [["_lang_Current", ["Check_Work_Order_and_Work_Order_Sceduler_started_amounts"]], "\n", ["_fld_Name", ["wo_production_lot"]], "ksSpace", ["_fld_ValueStr", ["wo_production_lot"]]]], ["_lang_Current", ["OK"]], "", "yes", ["cancel", "+", "no"]]]
                                ]
                              ]
                            ],
                            ["_tbl_WRITE_STATE", ["wos_tbl", "previous"]]
                          ]
                        ]
                      ]
                    ]
                  ]
                ],
                "else",
                [
                  ["wos__MATERIAL_AMOUNT_CHANGE", ["wo_started_amount"]],
                  [
                    "if", ["_wo_tOldState", "=", ["g.wo_sState_NotLoaded"]],
                    [
                      ["_wo_tNewState", "=", ["g.wo_sState_Loaded"]]
                    ]
                  ]
                ]
              ],
              [
                "if", ["_wo_tNewState", "<>", ""],
                [
                  ["_fld_VALUE_STR_SET", ["set", "wo_state", "_wo_tNewState"]],
                  ["wo_C_TILA", ["_wos_tProductionLot", "false"]]
                ]
              ]
            ]
          ]
        ]
      ]
    ],
    "wo__FAILED_AND_REMAINING_SET": [
      [
        "if", ["Count_parameters", ">", "1"],
        [
          ["_wo_tProductionLot", "=", ["arg1"]]
        ],
        "else",
        [
          ["_wo_tProductionLot", "=", ""]
        ]
      ],
      [
        "if", ["_wo_tProductionLot", "<>", ""],
        [
          ["_txt", "=", ["_wo_tProductionLot"]],
          ["_qry_Fld", ["0", ["wo_production_lot", "=", ["_txt"]], "", "false"]]
        ]
      ],
      [
        "if", [["_sel_RecsInSel", ["wo_tbl"]], ">", "0"],
        [
          [
            "if", [["wo_state", "=", ["g.wo_sState_Finished"]], "or", ["wo_state", "=", ["g.wo_sState_Canceled"]]],
            [
            ],
            "else",
            [
              ["wo_rFailedAmount_tmp", "=", "0"],
              ["wo_rRemaingAmount_tmp", "=", "0"],
              ["wos__FAILED_AND_REMAINING_GET", ["wo_production_lot", "all", "wo_rFailedAmount_tmp", "wo_rRemaingAmount_tmp"]],
              ["_wo_rFailedAmount", "=", ["wo_rFailedAmount_tmp"]],
              ["_wo_rRemainingAmount", "=", ["wo_rRemaingAmount_tmp"]],
              ["_wo_rRemainingAmount", "=", ["_wo_rRemainingAmount", "-", ["_fld_ValueReal", ["wo_produced_amount"]]]],
              [
                "if", [["wo_failed_amount", "<>", ["_wo_rFailedAmount"]], "or", ["wo_remaining_amount", "<>", ["_wo_rRemainingAmount"]]],
                [
                  ["_tbl_WRITE_STATE", ["wo_tbl", "true"]],
                  ["_rec_LOCKED_WAIT", ["wo_tbl", "true"]],
                  [
                    "if", ["OK", "=", "0"],
                    [
                      ["_wo_tErr", "=", ["concat", [["_lang_Current", ["Work_Order_was_locked"]], ": ", "wo_production_lot", "\n"]]],
                      ["_wo_tErr", "=", ["concat", ["_wo_tErr", ["_lang_Current", ["Work_Order_remaining_and_failed_amounts_were_not_updated"]]]]],
                      ["_err_MESSAGE", ["_wo_tErr", "Current_method_name", "false"]]
                    ],
                    "else",
                    [
                      ["_fld_VALUE_REAL_SET", ["set", "wo_failed_amount", "_wo_rFailedAmount"]],
                      ["_fld_VALUE_REAL_SET", ["set", "wo_remaining_amount", "_wo_rRemainingAmount"]],
                      ["_rec_SAVE", ["wo_tbl"]]
                    ]
                  ],
                  ["_tbl_WRITE_STATE", ["wo_tbl", "previous"]]
                ]
              ]
            ]
          ]
        ]
      ]
    ],
    "wo_C_TILA": [
      ["_wo_sValmEra", "=", ["arg1"]],
      ["_wo_fConfirm", "=", ["arg2"]],
      ["wo_PAIV_KU_TILAT", ["_wo_fConfirm"]],
      ["wo_PAIV_MR_TILA", ["0", ""]]
    ],
    "wo_PAIV_KU_TILAT": [
      [
        "if", ["Count_parameters", ">=", "1"],
        [
          ["_fCry", "=", ["arg1"]]
        ],
        "else",
        [
          ["_fCry", "=", "true"]
        ]
      ],
      [
        "if", [["_sel_RecsInTbl", ["wos_tbl"]], ">", "0"],
        [
          [
            "if", ["wo_state", "<>", ["g.wo_sState_Stopped"]],
            [
              ["_txt", "=", ["_fld_ValueStr", ["wo_production_lot"]]],
              ["_qry_Fld", ["0", ["wos_production_lot", "=", ["_txt"]], "", "false"]],
              [
                "if", [["_sel_RecsInSel", ["wos_tbl"]], ">", "0"],
                [
                  ["_sel_NAMED_SEL_COPY", ["wos_tbl", "wos_StateChange"]],
                  [
                    "if", [["wo_state", "=", ["wo_sState_NotLoaded"]], "or", ["wo_state", "=", ["g.wo_sState_Loaded"]]],
                    [
                      ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_NotLoaded"]], "*", "true"]],
                      ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_Loaded"]], "|*", "true"]],
                      ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_Stopped"]], "|*", "true"]],
                      ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_Paused"]], "|", "true"]]
                    ],
                    "elseif", ["wo_state", "=", ["g.wo_sState_Started"]],
                    [
                      ["wo_state", "=", ["g.wo_sState_Loaded"]],
                      ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_NotLoaded"]], "", "true"]]
                    ],
                    "elseif", [["wo_state", "=", ["g.wo_sState_Finished"]], "or", ["wo_state", "=", ["g.wo_sState_Canceled"]]],
                    [
                      [
                        "if", ["g.wo_lSetFinishedStateToAllWos", "=", "false"],
                        [
                          ["_sel_REDUCE", ["wos_tbl", "0"]]
                        ],
                        "else",
                        [
                          ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_NotLoaded"]], "*", "true"]],
                          ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_Loaded"]], "|*", "true"]],
                          ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_Paused"]], "|*", "true"]],
                          ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_Started"]], "|", "true"]]
                        ]
                      ]
                    ],
                    "elseif", ["false"],
                    [
                      ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_NotLoaded"]], "*", "true"]],
                      ["_qry_Fld", ["0", ["wos_work_phase_state", "=", ["g.wo_sState_Loaded"]], "|", "true"]],
                      ["wo_state", "=", ["g.wo_sState_Stopped"]]
                    ],
                    "else",
                    [
                      ["_sel_REDUCE", ["wos_tbl", "0"]]
                    ]
                  ],
                  [
                    "if", [["_sel_RecsInSel", ["wos_tbl"]], ">", "0"],
                    [
                      [
                        "if", ["_fCry"],
                        [
                          ["_wo_lGo", "=", ["_info_YesNoCancel", ["confirm", ["concat", [["_lang_Current", ["Do_you_want_to_change_open_work_order_schedule_states?"]], "\n", " ", "wo_state"]], "", "", "yes", "cancel"]]]
                        ],
                        "else",
                        [
                          ["_wo_lGo", "=", "yes"]
                        ]
                      ],
                      [
                        "if", ["_wo_lGo", "=", "yes"],
                        [
                          ["_tbl_WRITE_STATE", ["wos_tbl", "true"]],
                          ["_j", "=", ["_sel_RecsInSel", ["wos_tbl"]]],
                          ["_rec_FIRST", ["wos_tbl"]],
                          ["_wo_dDateCurrent", "=", ["_date_Current", ["true"]]],
                          [
                            "for", [["_i", "=", "1"], "_j"], "do",
                            [
                              ["_rec_LOCKED_WAIT", ["wos_tbl", "true"]],
                              [
                                "if", ["OK", "=", "1"],
                                [
                                  ["_fld_VALUE_STR_SET", ["set", "wos_work_phase_state", "wo_state"]],
                                  [
                                    "if", ["wo_state", "=", ["g.wo_sState_Finished"]],
                                    [
                                      ["_txt", "=", ""],
                                      ["_fld__VALUE_OLD", ["wos_work_phase_state", "_txt"]],
                                      ["_wo_tOldState", "=", ["_txt"]],
                                      [
                                        "if", [[["_fld_ValueDate", ["wos_act_end_date"]], "<>", "00.00.0000"], "and", ["_wo_tOldState", "=", ["g.wo_sState_Finished"]]],
                                        [
                                          ["IDLE"]
                                        ],
                                        "else",
                                        [
                                          ["_fld_VALUE_DATE_SET", ["set", "wos_act_end_date", "_wo_dDateCurrent"]]
                                        ]
                                      ]
                                    ]
                                  ],
                                  ["_rec_SAVE", ["wos_tbl"]]
                                ]
                              ],
                              ["_rec_NEXT", ["wos_tbl"]]
                            ]
                          ],
                          ["_tbl_WRITE_STATE", ["wos_tbl", "previous"]]
                        ]
                      ]
                    ]
                  ],
                  ["_sel_NAMED_SEL_USE", ["wos_tbl", "wos_StateChange"]],
                  ["_sel_NAMED_SEL_CLEAR", ["wos_tbl", "wos_StateChange"]]
                ]
              ]
            ]
          ]
        ]
      ]
    ],
    "wo_PAIV_MR_TILA": [
      ["ARRAY_TEXT", ["wo_atSorRecId_tmp", "0"]],
      ["ARRAY_DATE", ["wo_adSorDeliveryDate_tmp", "0"]],
      ["_wo_rProducedAmount", "=", ["arg1"]],
      ["_wo_tProduct", "=", ["arg2"]],
      [
        "if", ["wo_sales_order_id", "<>", ""],
        [
          [
            "if", [["_el_Tbl", "=", ["so_tbl"]], "or", ["_el_Tbl", "=", ["sor_tbl"]]],
            [
              ["_fld_VALUE_STR_SET", ["set", ["sor_production_state", ["_fld_ValueStr", ["wo_state"]]]]]
            ],
            "else",
            [
              ["_sel_NAMED_SEL_COPY", ["sor_tbl", "wo_StateChange"]],
              [
                "if", ["_wo_tProduct", "=", ""],
                [
                  [
                    "if", ["_el_InInput", "=", "false"],
                    [
                      ["_sel_RELATE_ONE", ["w_work_position_num_id", "wo_work_position_num_id"]]
                    ]
                  ],
                  ["_wo_tProduct", "=", ["_fld_ValueStr", ["w_product_id"]]]
                ]
              ],
              ["_wo_lSorSelection", "=", ["wo__OpenSorFind", ["wo_production_lot", "_wo_tProduct"]]],
              [
                "if", ["_wo_lSorSelection", ">", "0"],
                [
                  ["_sel__SEL_TO_ARR_TWO", ["sor_record_id", "wo_atSorRecId_tmp", "sor_delivered_date", "wo_adSorDeliveryDate_tmp"]],
                  ["SORT_ARRAY", ["wo_adSorDeliveryDate_tmp", "wo_atSorRecId_tmp", ">"]],
                  ["_tbl_WRITE_STATE", ["sor_tbl", "true"]],
                  [
                    "for", [["_wo_lSorIndex", "=", "1"], "_wo_lSorSelection"], "do",
                    [
                      ["_qry_Fld", ["0", ["sor_record_id", "=", ["wo_atSorRecId_tmp[_wo_lSorIndex]"]], "", "false"]],
                      [
                        "if", [["_sel_RecsInSel", ["sor_tbl"]], ">", "0"],
                        [
                          [
                            "if", [["wo_state", "=", ["sor_production_state"]], "and", ["g.wo_lSaveProducedAmountToSor", "=", "false"]],
                            [
                              ["IDLE"]
                            ],
                            "else",
                            [
                              ["_rec_LOCKED_WAIT", ["sor_tbl", "true"]],
                              [
                                "if", ["OK", "=", "1"],
                                [
                                  ["_fld_VALUE_STR_SET", ["set", "sor_production_state", "wo_state"]],
                                  [
                                    "if", [["g.wo_lSaveProducedAmountToSor", "=", "true"], "and", ["_wo_rProducedAmount", "<>", "0"]],
                                    [
                                      [
                                        "if", ["_wo_lSorSelection", "=", "1"],
                                        [
                                          ["_wo_rCollectedAmount", "=", ["Num", ["_fld_ValueStr", ["sor_collected_amount"]]]],
                                          ["_wo_rCollectedAmount", "=", ["_wo_rCollectedAmount", "+", "_wo_rProducedAmount"]]
                                        ],
                                        "else",
                                        [
                                          ["_wo_rCollectedAmount", "=", ["Num", ["_fld_ValueStr", ["sor_collected_amount"]]]],
                                          [
                                            "if", ["_wo_rCollectedAmount", "<", ["sor_waiting_for_delivery"]],
                                            [
                                            ]
                                          ]
                                        ]
                                      ],
                                      ["_fld_VALUE_STR_SET", ["set", "sor_collected_amount", ["String", ["_wo_rCollectedAmount"]]]]
                                    ]
                                  ],
                                  ["_rec_SAVE", ["sor_tbl"]]
                                ]
                              ],
                              ["_rec_UNLOAD", ["sor_tbl"]]
                            ]
                          ]
                        ]
                      ]
                    ]
                  ],
                  ["_tbl_WRITE_STATE", ["sor_tbl", "previous"]],
                  ["_rec_UNLOAD", ["sor_tbl"]],
                  ["ARRAY_TEXT", ["wo_atSorRecId_tmp", "0"]],
                  ["ARRAY_DATE", ["wo_adSorDeliveryDate_tmp", "0"]]
                ]
              ],
              ["_sel_NAMED_SEL_USE", ["sor_tbl", "wo_StateChange"]],
              ["_sel_NAMED_SEL_CLEAR", ["sor_tbl", "wo_StateChange"]]
            ]
          ]
        ]
      ]
    ],
    "wo_scMATERIAL_EST_ARRIVAL_DATE": [
      ["_wo_tMessage", "=", ["concat", [["_lang_Current", ["Material_purchase_order_exists"]], ". ", "\n"]]],
      ["_wo_tMessage", "=", ["concat", ["_wo_tMessage", ["_lang_Current", ["Date_changes_must_be_done_via_purchase_order"]], "."]]],
      [
        "if", [["wo_MaterialDateSetAllow", ["wo_production_lot", "_wo_tMessage"]], "=", "false"],
        [
          ["_err_FIX", ["concat", ["Current_method_name", ": Return_old_value_to_include_cell"]]],
          [
            "if", [["_sel_RecsInSel", ["por"], ">", "0"]],
            [
              [
                "if", ["por_confirmed_arrival_date", "=", "00.00.0000"],
                [
                  ["por_confirmed_arrival_date", "=", ["por_requested_delivery_date"]]
                ]
              ],
              ["_fld_VALUE_DATE_SET", ["set", "wo_material_est_arrival_date", "por_confirmed_arrival_date"]]
            ]
          ]
        ]
      ]
    ]
  }
}
