{
  "info": "",
  "field": {
    "single_click": [
      ["por_STOCK_ALARM"],
      ["por_tPrevProductionLot", "=", ["por_production_lot"]]
    ],
    "sor": [
      ["por_scBEFORE"]
    ],
    "por_product_id": [
      ["por_scTUOTE"],
      ["por_STOCK_ALARM"]
    ],
    "por_stock_event": [],
    "por_unit_total": [
      ["por_KPL_MAARA"]
    ],
    "por_work_phase_number": [
      ["por_ADDITIONAL_DATA_FROM_WOS"]
    ],
    "por_work_position_number_id": [],
    "por_production_lot": [
      ["por_scPRODUCTION_LOT"]
    ],
    "por_purchase_price_total": [
      ["por_scOSTOHINTA_YH"]
    ],
    "por_delivery_state": [
      ["por_scDELIVERY_STATE"]
    ],
    "por_order_amount": [
      ["por_TILATTU_MRA"]
    ],
    "por_order_unit": [],
    "por_row_number": [
      ["por_scRIVINUMERO"]
    ],
    "por_confirmed_arrival_date": [
      [
        "if", ["por_requested_delivery_date", "=", "00.00.0000"],
        [
          ["por_requested_delivery_date", "=", ["por_confirmed_arrival_date"]]
        ]
      ],
      ["_fld_VALUE_LONG_SET", ["set", "por_confirmation_state", "1"]],
      ["por_scENS_TOIM_PV"],
      ["por_lVahvVko", "=", ["aaC_Date_Week", ["por_confirmed_arrival_date"]]],
      ["por_WO_UPDATE", ["por_confirmed_arrival_date", "false", ""]]
    ],
    "por_type": [],
    "por_ingo": [],
    "por_price_unit": [
      ["por_scAHINTA"]
    ],
    "por_purchase_order_id": [],
    "por_parcel_code": [
      ["stpa_hae_mitta_kpl", ["por_product_id"], "por_parcel_code", "por_dimension", "por_unit_total", "por_parcel_type", "por_stock_position"]
    ],
    "por_explanation": [],
    "por_purchase_order_id": [
      ["por_scOSTOKOODI"]
    ],
    "por_vat_percentage": [
      ["por_scLVV_PROSENTT"]
    ],
    "por_vat_price": [],
    "por_delivered_amount": [
      ["por_scTOIMITETTU_Y"]
    ],
    "por_partial_delivery_number": [],
    "por_in_accounts_payable": [],
    "por_company_id": [],
    "por_order_state": [],
    "por_order_row": [],
    "por_order_date": [
      [
        "if", ["_fi_InFullpage", "=", "true"],
        [
          ["por_lTilVko", "=", ["aaC_Date_Week", ["por_order_date"]]]
        ]
      ]
    ],
    "por_date_of_arrival": [
      ["por_WO_UPDATE", ["por_date_of_arrival", "false", ""]],
      [
        "if", ["_fi_InFullpage", "=", "true"],
        [
          ["por_lTuloVko", "=", ["aaC_Date_Week", ["por_date_of_arrival"]]]
        ]
      ]
    ],
    "por_dimension": [
      ["por_KPL_MAARA"]
    ],
    "por_sales_order_id": [],
    "por_tariff_heading": [],
    "por_discount_percentage": [
      ["por_L_RIVISUMMAT"]
    ],
    "por_dicount_amount": [
      ["por_ALE_L_RIVISUM"]
    ],
    "por_stock_position": [],
    "por_parcel_type": [],
    "por_first_confirm_deliv_date": [
      ["por_sc1_VAH_TO_PV"]
    ],
    "por_subcontract_sent_date": [],
    "por_requested_delivery_date": [
      [
        "if", ["_fi_InFullpage", "=", "true"],
        [
          ["por_requested_delivery_date", "=", ["aaC_Date_Week", ["por_requested_delivery_date"]]]
        ]
      ],
      ["por_WO_UPDATE", ["por_requested_delivery_date", "false", ""]]
    ],
    "por_supplier_material_code": [],
    "por_order_amount_2": [
      ["por_scMAARA_YKS2", ["por_product_id", "por_order_amount", "por_order_amount_2"]],
      ["por_L_RIVISUMMAT"],
      ["por_STOCK_ALARM"],
      [
        "if", ["!aaOptionKey"],
        [
          ["stpa_S_KPL_MITTA", ["por_product_id", "por_dimension", "por_unit_total", "por_order_amount", "por_order_amount_2"]]
        ]
      ],
      ["por_WO_UPDATE", ["por_order_amount", "true", ""]]
    ],
    "por_cost_center": [],
    "por_price_confirmation": [],
    "por_purchase_costs": [
      ["por_PRODUCT_PRICE_UPDATE"]
    ],
    "por_lme_price": [],
    "por_material_stock_state": [],
    "por_xml_value": [],
    "por_transfer_id": [],
    "por_additional_data": [],
    "por_confirmation_state": [
      [
        "if", ["_fld_ValueLong", ["por_confirmation_state"], "=", "1"],
        [
          [
            "if", ["_fld_ValueDate", ["por_first_confirm_deliv_date"], "=", "00.00.0000"],
            [
              ["_por_dConfirmed", "=", ["_fld_ValueDate", ["por_confirmed_arrival_date"]]],
              [
                "if", ["_por_dConfirmed", "<>", "00.00.0000"],
                [
                  ["_fld_VALUE_DATE_SET", ["set", "por_first_confirm_deliv_date", "_por_dConfirmed"]]
                ]
              ]
            ]
          ]
        ]
      ]
    ],
    "por_delivery_to_customer": [
      ["por_ff_delivery_to_customer", "=", ["_fld_ValueLong", ["por_delivery_to_customer"]]]
    ]
  },
  "function": {
    "por_scTUOTE": [
      [
        "if", ["pr_fValilis"],
        [
          ["pr_fValilis", "=", "false"],
          ["xpRealFile", "=", ["po"]],
          ["por_product_id", "=", ["pr_sTunnus"]],
          ["RELATE_ONE", ["por_product_id"]]
        ]
      ],
      [
        "if", ["pr_not_in_use"],
        [
          ["xCRY", ["Tuote_on_merkitty_kaytosta_poistetuksi."]]
        ]
      ],
      [
        "if", ["po_purchase_order_id", "<>", ["por_purchase_order_id"]],
        []
      ],
      ["_por_rAmount", "=", ["_fld_valuereal", ["pr_kmin_purchase_amount__unit"]]],
      [
        "if", ["_por_rAmount", ">", "0"],
        [
          ["por_order_amount", "=", ["_por_rAmount"]]
        ]
      ],
      ["por_supplier_material_code", "=", ["pr_supplier_material_code"]],
      ["por_stock_position", "=", ["pr_stock_position"]],
      ["por_parcel_code", "=", ["pr_parcel_code"]],
      [
        "if", ["co_company_id", "<>", ["po_company_id"]],
        [
          ["RELATE_ONE", ["po_company_id"]]
        ]
      ],
      [
        "if", ["co_stock_position", "<>", ""],
        [
          ["por_stock_position", "=", ["co_stock_position"]]
        ]
      ],
      ["por_work_position_number_id", "=", ["pr_work_position_num_id"]],
      ["por_order_unit", "=", ["pr_unit"]],
      ["por_syks2", "=", ["pr_unit_2"]],
      ["por_scmaara_yks1", ["por_product_id", "por_order_amount_2", "por_order_amount"]],
      ["por_tariff_heading", "=", ["pr_tariff_heading"]],
      [
        "if", ["su_supplier_id", "<>", ["po_supplier_id"]],
        [
          ["RELATE_ONE", ["po_supplier_id"]]
        ]
      ],
      ["pr__name_and_unit_get", ["por_product_id", "su_language", "por_explanation", "por_order_unit"]],
      ["_por_rprice__unit", "=", "0"],
      ["_por_lwpeselsize", "=", "0"],
      [
        "if", ["por_work_position_number_id", "<>", ""],
        [
          ["_por_lWpeSelSize", "=", ["_qry_Fld", ["wpe_tbl", ["wpe_kWork__Position_Num_id", "=", ["por_work_position_number_id"]], "*", "false"]]],
          ["_por_lWpeSelSize", "=", ["_qry_Fld", ["wpe_tbl", ["wpe_supplier_id", "=", ["po_supplier_id"]], "&", "false"]]],
          [
            "if", ["_por_lWpeSelSize", ">", "0"],
            [
              [
                "if", ["por_work_phase_number", ">", "0"],
                [
                  ["_por_lWpeSelSize", "=", ["_qry_Fld", ["wpe_tbl", ["wpe_phase_number", "=", ["por_work_phase_number"]], "", "true"]]]
                ],
                "else",
                [
                  ["por_work_phase_number", "=", ["wpe_phase_number"]]
                ]
              ],
              [
                "if", ["_por_lWpeSelSize", ">", "0"],
                [
                  ["_por_rPrice__Unit", "=", ["_fld_ValueReal", ["wpe_subcont_purc_price_unit"]]]
                ]
              ]
            ]
          ]
        ]
      ],
      ["_por_lsubcontractpurchasecodeis", "=", ["por_subcontractpurchasecodeis", ["por_purchase_order_code_id"]]],
      [
        "if", [["_por_lWpeSelSize", ">", "0"], "and", ["_por_lSubcontractPurchaseCodeIs", "=", "true"]],
        [
          ["por_price_unit", "=", ["cur__BuyConvert", ["_por_rPrice__Unit", "cur__DefaultCurre", "po_currency_id"]]]
        ]
      ],
      ["por_tcurrency", "=", ["po_currency_id"]],
      ["pr__purch_price_and_matcode_get", ["por_product_id", "po_supplier_id", "por_rpurchaseprice", "por_rdiscountpercentage", "por_tcurrency", "por_tsuppliermaterialcode"]],
      [
        "if", ["po_currency_id", "<>", ["por_tCurrency"]],
        [
          ["_txt", "=", ["_lang_Current", ["concat", ["Purchase_order_currency_is_different_than_product_supplier_currency", "\n"]]]],
          ["_txt", "=", ["concat", ["_txt", ["_tbl_Name", ["po_tbl"]], ": ", "po_currency_id", " / ", ["_tbl_Name", ["prsu_kTbl"]], ": ", "por_tCurrency", ["_err_CRY", ["_txt", "true"]]]]]
        ]
      ],
      [
        "if", ["_por_rPrice__Unit", "=", "0"],
        [
          ["por_price_unit", "=", ["por_rPurchasePrice"]],
          ["por_discount_percentage", "=", ["por_rDiscountPercentage"]]
        ]
      ],
      ["por_supplier_material_code", "=", ["por_tsuppliermaterialcode"]],
      [
        "if", ["g.pr_lSeliKopi", "=", "1"],
        [
          [
            "if", ["por_explanation", "<>", ""],
            [
              ["por_explanation", "=", ["concat", ["por_explanation", "\n"]]]
            ]
          ],
          ["por_explanation", "=", ["concat", ["por_explanation", "pr_explanation"]]]
        ],
        "elseif", ["g.pr_lSeliKopi", "=", "2"],
        [
          ["por_explanation", "=", ["pr_explanation"]]
        ]
      ],
      [
        "if", ["false"],
        [
          [
            "if", ["pr_stock_parcel_in_use"],
            [
              ["QUERY", ["stpa", ["stpa_produc_id", "=", ["por_product_id"]]]],
              [
                "if", [["Records_in_selection", ["stpa"]], ">=", "1"],
                [
                  ["st_sTuote", "=", ["por_production_id"]],
                  ["DIALOG", ["stev", "D_Kohdistus"]],
                  [
                    "if", ["OK", "=", "1"],
                    [
                      ["por_parcel_code", "=", ["stpa_parcel_code"]],
                      ["por_price_unit", "=", ["stpa_purchase_price_unit"]]
                    ],
                    "else",
                    [
                      ["por_parcel_code", "=", ""]
                    ]
                  ]
                ],
                "else",
                [
                  ["por_parcel_code", "=", ""]
                ]
              ]
            ]
          ]
        ]
      ],
      ["por_purchase_order_id", "=", ["poc__newcodeget", ["pr_purchase_order_code_id"]]],
      [
        "if", ["poc_purchase_order_code_id", "<>", ["por_purchase_order_code_id"]],
        [
          ["RELATE_ONE", ["por_purchase_order_code_id"]]
        ]
      ],
      ["por_vat_percentage", "=", ["poc_vat_percentage"]],
      [
        "if", ["pr_cost_center", "<>", ""],
        [
          ["por_cost_center", "=", ["pr_cost_center"]]
        ],
        "else",
        [
          ["por_cost_center", "=", ["po_cost_center"]]
        ]
      ],
      [
        "if", ["por_cost_center", "=", ""],
        [
          ["por_cost_center", "=", ["poc_target"]]
        ]
      ],
      ["por_L_RIVISUMMAT"],
      ["por_STOCK_ALARM"]
    ],
    "por_STOCK_ALARM": [
      ["pr_nc__PRODUCT_STATE_INFO", ["por_product_id", "por_order_amount", "00.00.0000", "1", "false"]]
    ],
    "por_scBEFORE": [
      ["por_purchase_order_id", "=", ["po_purchase_order_id"]],
      ["por_row_number", "=", [["MAX", ["por_row_number"]], "+", "1"]],
      ["por_order_row", "=", ["vac_valeravaihe", ["por_purchase_order_id", "por_row_number", "por_partial_delivery_number"]]],
      [
        "if", ["g.por_requesteddeliverydate_set", "=", "true"],
        [
          ["por_confirmed_arrival_date", "=", ["po_first_delivery_date"]]
        ]
      ],
      [
        "if", ["g.por_confirmedarrivaldate_set", "=", "true"],
        [
          ["por_confirmed_arrival_date", "=", ["po_first_delivery_date"]]
        ]
      ],
      [
        "if", ["por_requested_delivery_date", "=", "00.00.0000"],
        [
          ["por_requested_delivery_date", "=", ["por_confirmed_arrival_date"]]
        ]
      ],
      ["por_order_date", "=", ["por_order_date"]],
      ["por_order_amount", "=", "1"],
      ["por_scMAARA_YKS1", ["por_product_id", "por_order_amount_2", "por_order_amount"]],
      ["por_order_state", "=", ["po_state"]],
      ["por_type", "=", ["po_order_type"]],
      [
        "if", ["por_tilaaja", "<>", ""],
        [
          ["por_company_id", "=", "por_tilaaja"]
        ],
        "else",
        [
          "if", ["por_company_id", "<>", ""],
          [
            ["por_tilaaja", "=", ["po_company_id"]],
            ["por_company_id", "=", ["por_tilaaja"]]
          ]
        ]
      ],
      ["por_unit_total", "=", "1"]
    ],
    "por_KPL_MAARA": [
      [
        "if", ["!aaOptionKey"],
        [
          ["RELATE_ONE", ["por_product_id"]],
          [
            "if", ["pr_effect_of_fixed_size", "=", "1"],
            [
              ["por_order_amount", "=", ["por_dimension", "*", "por_unit_total"]],
              ["por_order_amount", "=", ["Round", ["por_order_amount", ["g.por_orderamountrouding"], ["por_orderamountrouding"]]]],
              ["por_scMAARA_YKS1", ["por_product_id", "por_order_amount_2", "por_order_amount"]]
            ],
            "elseif", ["pr_effect_of_fixed_size", "=", "2"],
            [
              ["por_order_amount_2", "=", ["por_dimension", "*", "por_unit_total"]],
              ["por_scMAARA_YKS2", ["por_product_id", "por_order_amount", "por_order_amount_2"]]
            ]
          ]
        ]
      ],
      ["por_L_RIVISUMMAT"]
    ],
    "por_ADDITIONAL_DATA_FROM_WOS": [
      [
        "if", [["por_production_lot", "<>", ""], "and", ["por_work_phase_number", ">", "0"]],
        [
          ["_por_lWosFound", "=", ["wos__Select_Create", ["por_production_lot", "por_work_phase_number", "false"]]],
          [
            "if", ["_por_lWosFound", ">", "0"],
            [
              ["_por_tAdditionalDate", "=", ["_fld_ValueStr", ["wos_additional_data"]]],
              ["_fld_VALUE_STR_SET", ["set", ["por_additional_data", "_por_tAdditionalDate"]]]
            ]
          ]
        ]
      ]
    ],
    "por_scPRODUCTION_LOT": [
      [
        "if", ["por_production_lot", "<>", ""],
        [
          ["_txt", "=", ["por_production_lot"]],
          [
            "if", [["_qry_Fld", ["wo_tbl", ["wo_production_lot", "=", ["_txt"]], "", "false"]], ">", "0"],
            [
              ["por_work_position_number_id", "=", ["_fld_ValueStr", ["wo_work_position_num_id"]]]
            ]
          ],
          ["por_ADDITIONAL_DATA_FROM_WOS"]
        ]
      ],
      ["por_GET_EXPLANATION_FROM_WME"],
      [
        "if", ["por_production_lot", "<>", ""],
        [
          ["por_WO_UPDATE", ["por_delivered_amount", "true", ""]],
          ["por_WOS_UPDATE"],
          ["por_Sor_FIELD_VALUE_TO_por_SET"]
        ],
        "elseif", ["por_tPrevProductionLot", "<>", ""],
        [
          [
            "if", [["_qry_Fld", ["wo_tbl", ["wo_production_lot", "=", ["por_tPrevProductionLot"]], "", "false"]], ">", "0"],
            [
              ["_por_lWosFound", "=", ["wos__Select_Create", ["por_tPrevProductionLot", "0", "false"]]],
              [
                "if", ["_por_lWosFound", ">", "0"],
                [
                  [
                    "if", [[["Find_in_array", ["g.wo_asOpenStates", "wos_work_phase_state"]], "<=", "0"], "or", ["wos_work_phase_state", "=", ["g.wo_state_started"]]],
                    [
                      ["_por_tAskInfo", "=", ["_lang_Current", ["Is_there_any_other_purchase_order_rows_to_this_work_order?"]]],
                      ["_por_tAskInfo", "=", ["concat", ["_por_tAskInfo", "\n", "\n", ["_lang_Current", ["If_there_is_not, material_phase_is_changed_back_to 'open'"]]]]],
                      ["_por_tAskInfo", "=", ["concat", ["_por_tAskInfo", "\n", ["_fld_Name", ["por_production_lot"]], ": ", "por_tPrevProductionLot"]]],
                      ["_por_lOtherPorRowsExist", "=", ["_info_YesNoCancel", ["confirm", "_por_tAskInfo", "", "", "no", "cancel"]]],
                      [
                        "if", ["_por_lOtherPorRowsExist", "=", "no"],
                        [
                          ["_tbl_WRITE_STATE", ["wos_tbl", "true"]],
                          ["_rec_LOCKED_WAIT", ["wos_tbl", "true"]],
                          [
                            "if", ["OK", "=", "1"],
                            [
                              [
                                "if", [["_fld_ValueStr", ["wo_state"]], "=", ["g.wo_state_loaded"]],
                                [
                                  ["_fld_VALUE_STR_SET", ["set", "wos_work_phase_state", "g.wo_sState_Loaded"]]
                                ],
                                "else",
                                [
                                  ["_fld_VALUE_STR_SET", ["set", "wos_work_phase_state", "g.wo_sState_NotLoaded"]]
                                ]
                              ],
                              ["_rec_SAVE", ["wos_tbl"]]
                            ]
                          ],
                          ["_tbl_WRITE_STATE", ["wos_tbl", "previous"]]
                        ]
                      ]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ],
      ["por_tPrevProductionLot", "=", ["por_production_lot"]]
    ],
    "por_GET_EXPLANATION_FROM_WME": [
      [
        "if", [["_fld_ValueStr", ["por_type"]], "=", ["g.po_tType_Material"]],
        [
          ["_por_lReplace", "=", "true"],
          ["_txt", "=", ["_fld_ValueStr", ["por_work_position_number_id"]]],
          ["_qry_Fld", ["wme_kTbl", ["wme_work_position_num_id", "=", ["_txt"]], "*", "false"]],
          ["_txt", "=", ["_fld_ValueStr", ["por_product_id"]]],
          [
            "if", [["_qry_Fld", ["wme_kTbl", ["wme_raw_material_id", "=", ["_txt"]], "&", "false"]], ">", "0"],
            [
              [
                "if", [["wme_explanation", "<>", ""], "and", ["wme_explanation", "<>", ["por_explanation"]]],
                [
                  ["_sel_RELATE_ONE", ["pr_kProduct_ID", "por_product_id"]],
                  [
                    "if", [["por_explanation", "<>", ["pr_name"]], "and", ["por_explanation", "<>", ""]],
                    [
                      ["_por_tTxt", "=", ["_lang_Current", ["concat", ["Do_you_want_to_get_row_explanation_from_Work_Estimated_Material?", "\n", "\n"]]]],
                      ["_por_tTxt", "=", ["concat", ["_por_tTxt", ["_fld_Name", ["por_explanation"]], ": ", "wme_explanation" ]]],
                      [
                        "if", [["_info_YesNoCancel", ["confirm", "_por_tTxt", "", "", "yes", "cancel"]], "=", "no"],
                        [
                          ["_por_lReplace", "=", "false"]
                        ]
                      ]
                    ]
                  ],
                  [
                    "if", ["_por_lReplace", "=", "true"],
                    [
                      ["_fld_VALUE_STR_SET", ["set", "por_explanation", "wme_explanation"]]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ],
    "por_Sor_FIELD_VALUE_TO_por_SET": [
      [
        "if", ["g.por_tCopySalesOrderRowFldValue", "<>", ""],
        [
          ["_txt", "=", ["_str_Parse", ["g.por_tCopySalesOrderRowFldValue", ";", "1"]]],
          ["_por_lSalesOrderRowFld", "=", ["_var_ConstantNameToLong", ["_txt"]]],
          ["_txt", "=", ["_str_Parse", ["g.por_tCopySalesOrderRowFldValue", ";", "2"]]],
          ["_por_lPurchaseOrderRowFld", "=", ["_var_ConstantNameToLong", ["_txt"]]],
          [
            "if", [["_por_lSalesOrderRowFld", "<>", "0"], "and", ["_por_lPurchaseOrderRowFld", "<>", "0"]],
            [
              [
                ["_txt", "=", ["_fld_ValueStr", ["por_production_lot"]]],
                "if", ["_txt", "<>", ""],
                [
                  ["_qry_Fld", ["wo_tbl", ["wo_production_lot", "=", ["por_production_lot"]], "", "false"]],
                  ["_por_lWoSelection", "=", ["_sel_RecsInSel", ["wo_tbl"]]],
                  [
                    "if", ["_por_lWoSelection", ">", "0"],
                    [
                      ["_txt", "=", ["_fld_ValueStr", ["wo_sales_order_id"]]],
                      ["_long", "=", ["_fld_ValueLong", ["wo_sales_order_row_id"]]],
                      [
                        "if", [["_txt", "<>", ""], "and", ["_long", ">", "0"]],
                        [
                          ["_qry_Fld", ["0", ["sor_sales_order_id", "=", ["_txt"]], "*", "false"]],
                          ["_qry_Fld", ["0", ["sor_row_number", "=", ["_long"]], "&", "false"]],
                          ["_por_lSorSelection", "=", ["_sel_RecsInSel", ["sor_tbl"]]],
                          [
                            "if", ["_por_lSorSelection", ">", "0"],
                            [
                              ["_txt", "=", ["_fld_ValueStr", ["_por_lSalesOrderRowFld"]]],
                              ["_fld_VALUE_STR_SET", ["set", "_por_lPurchaseOrderRowFld", "_txt"]]
                            ]
                          ]
                        ]
                      ]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ],
    "por_scOSTOHINTA_YH": [
      [
        "if", ["por_delivered_amount", ">", "0"],
        [
          ["_por_rAmount", "=", ["por_delivered_amount"]]
        ],
        "elseif", ["por_order_amount", ">", "0"],
        [
          ["_por_rAmount", "=", ["por_order_amount"]]
        ],
        "else",
        [
          ["_por_rAmount", "=", "0"]
        ]
      ],
      ["_por_rDivider", "=", ["_por_rAmount", "-", [["_por_rAmount", "*", "por_discount_percentage"], "/", "100"]]],
      [
        "if", [["_por_rAmount", "<>", "0"], "and", ["_por_rDivider", "<>", "0"]],
        [
          ["por_price_unit", "=", ["por_purchase_price_total", "/", "_por_rDivider"]],
          [
            "if", ["por_discount_percentage", "<>", "0"],
            [
              ["por_discount_amount", "=", ["Round", [[["por_price_unit", "*", "_por_rAmount", "*", "por_discount_percentage"], "/", "100"], "2"]]]
            ]
          ],
          ["por_price_unit", "=", ["Round", ["por_price_unit", "g.pr_iPyorAHin"]]]
        ],
        "else",
        [
          ["por_L_RIVISUMMAT"]
        ]
      ]
    ],
    "por_scDELIVERY_STATE": [
      [
        "if", ["por_delivery_state", "=", ""],
        [
          ["por_date_of_arrival", "=", "00.00.0000"]
        ],
        "else",
        [
          ["por_date_of_arrival", "=", ["_date_Current", ["true"]]],
          [
            "if", ["por_confirmed_arrival_date", "=", "00.00.0000"],
            [
              ["por_confirmed_arrival_date", "=", ["por_date_of_arrival"]]
            ]
          ]
        ]
      ],
      ["por_wo_update", ["por_delivered_amount", "true", ""]],
      ["por_WOS_UPDATE"],
      ["por_wos_first_phase_update", ["true"]]
    ],
    "por_WOS_UPDATE": [
      [
        "if", ["g.por_lChangeWosAmount", ">", "0"],
        [
          [
            "if", [["por_type", "=", ["g.po_tType_SubContract"]], "and", ["g.bit", ["por_lChangeWosAmount", "1"]]],
            [
              ["_por_lContinue", "=", "true"]
            ],
            "elseif", [["por_type", "=", ["g.po_tType_Material"]], "and", ["g.bit", ["por_lChangeWosAmount", "0"]]],
            [
              ["_por_lContinue", "=", "true"]
            ],
            "else",
            [
              ["_por_lContinue", "=", "false"]
            ]
          ],
          [
            "if", ["_por_lContinue", "=", "true"],
            [
              [
                "if", ["por_production_lot", "<>", ""],
                [
                  [
                    "if", ["por_type", "=", ["g.po_tType_SubContract"]],
                    [
                      ["_por_lPhaseNum", "=", ["_fld_ValueLong", ["por_work_phase_number"]]]
                    ],
                    "else",
                    [
                      ["_por_lPhaseNum", "=", "0"]
                    ]
                  ],
                  ["_por_rWosProducedAmount", "=", ["por_WosAmountsUpdate", ["por_production_lot", "_por_lPhaseNum", "false"]]],
                  ["_rec_UNLOAD", ["wo_tbl"]],
                  ["_rec_UNLOAD", ["wos_tbl"]]
                ]
              ]
            ]
          ]
        ]
      ]
    ],
    "por_WosAmountsUpdate": [
      ["_por_rWosQuantity", "=", "0"],
      ["_por_tProductionLot", "=", ["arg1"]],
      ["_por_lPhaseNum", "=", ["arg2"]],
      ["_por_lAskFirstPhaseUpdate", "=", ["arg3"]],
      ["_por_lOK", "=", "false"],
      ["_por_lContinue", "=", "true"],
      ["_por_tWorkName", "=", ""],
      ["_por_tWorkProduct", "=", ""],
      ["_por_tLoadGroup", "=", ""],
      [
        "if", [["por_type", "=", ["g.po_tType_Material"]], "and", ["_por_lPhaseNum", "=", "1"]],
        [
          ["_por_lFirstPhaseUpdate", "=", "true"],
          ["_sel_RELATE_ONE", ["pr_product_id", "por_product_id"]],
          [
            "if", ["pr_work_load_group", "=", ""],
            [
              ["pr_work_load_group", "=", ["g.po_tLoadGroupToFinish"]]
            ]
          ],
          [
            "if", ["pr_work_load_group", "=", ""],
            [
              ["_por_lContinue", "=", "false"]
            ]
          ]
        ],
        "else",
        [
          ["_por_lFirstPhaseUpdate", "=", "false"]
        ]
      ],
      [
        "if", ["_por_lContinue", "=", "true"],
        [
          ["_por_lWosFound", "=", ["wos_Select_Create", ["_por_tProductionLot", "_por_lPhaseNum", "false"]]],
          [
            "if", ["_por_lWosFound", ">", "0"],
            ["COMPILER_wo"],
            [
              "if", [["Find_in_array", ["g.wo_asOpenStates", "wos_work_phase_state"]], ">", "0"],
              [
                [
                  "if", ["_por_lFirstPhaseUpdate", "=", "true"],
                  [
                    ["_por_lContinue", "=", "false"],
                    [
                      "if", ["wos_work_load_group_id", "=", ["pr_work_load_group"]],
                      [
                        ["_por_lUpdate", "=", "yes"],
                        [
                          "if", ["_por_lAskFirstPhaseUpdate", "=", "true"],
                          [
                            ["_txt", "=", ["por_work_position_number_id"]],
                            [
                              "if", [["_qry_Fld", ["w_tbl", ["w_work_position_num_id", "=", "_txt"], "", "false"]], ">", "0"],
                              [
                                ["_por_tWorkName", "=", ["_fld_ValueStr", ["w_name"]]],
                                ["_por_tWorkProduct", "=", ["_fld_ValueStr", ["w_product_id"]]]
                              ]
                            ],
                            ["_por_tAskInfo", "=", ["concat", [["_lang_Current", ["Raw_material"]], ": ", "por_product_id", "\n"]]],
                            ["_por_tAskInfo", "=", ["concat", ["_por_tAskInfo", "wos_work_load_group_id", ": ", "pr_work_load_group", "\n"]]],
                            ["_por_tAskInfo", "=", ["concat", ["_por_tAskInfo", "wo_production_lot", ": ", "_por_tProductionLot", "\n"]]],
                            ["_por_tAskInfo", "=", ["concat", ["_por_tAskInfo", "w_product_id", ": ", "w_product_id", "\n"]]],
                            ["_por_tAskInfo", "=", ["concat", ["_por_tAskInfo", "w_name", ": ", "w_name"]]],
                            [
                              "if", ["por_delivery_state", "=", ["g.por_tDeliveryState_PartialDeliv"]],
                              [
                                ["_por_tAskInfo", "=", ["concat", [["_lang_Current", ["Do_you_want_to_mark_first_Work_Phase_started?"]], "\n", "\n", "_por_tAskInfo"]]],
                                ["_por_lUpdate", "=", ["_info_YesNoCancel", ["confirm", "_por_tAskInfo", "", "", "yes", "cancel"]]]
                              ],
                              "elseif",["por_delivery_state", "=", ["g.por_tDeliveryState_Delivered"]],
                              [
                                ["_por_tAskInfo", "=", ["concat", [["_lang_Current", ["Do_you_want_to_mark_first_Work_Phase_finished?"]], "\n", "\n", "_por_tAskInfo"]]],
                                ["_por_lUpdate", "=", ["_info_YesNoCancel", ["confirm", "_por_tAskInfo", "", "", "yes", "cancel"]]]
                              ]
                            ]
                          ]
                        ],
                        [
                          "if", ["_por_lUpdate", "=", "yes"],
                          [
                            ["_por_lContinue", "=", "true"]
                          ]
                        ]
                      ]
                    ]
                  ],
                  "else",
                  [
                    ["_por_lContinue", "=", "true"],
                    [
                      "if", ["por_type", "=", ["g.po_tType_SubContract"]],
                      [
                        ["_bool", "=", "false"],
                        ["_fld_VALUE", ["get", "wos_subcontract", "bool"]],
                        [
                          "if", ["_bool", "=", "false"],
                          [
                            ["_por_lContinue", "=", "false"]
                          ]
                        ]
                      ]
                    ]
                  ]
                ],
                [
                  "if", ["_por_lContinue", "=", "true"],
                  [
                    [
                      "if", ["por_delivery_state", "=", ["g.por_tDeliveryState_Open"]],
                      [
                        ["wos_work_phase_state", "=", ["g.wo_sState_Loaded"]]
                      ],
                      "elseif", ["por_delivery_state", "=", ["g.por_tDeliveryState_PartialDeliv"]],
                      [
                        ["wos_work_phase_state", "=", ["g.wo_sState_Started"]]
                      ],
                      "elseif", ["_por_tDeliveryState", "=", ["g.por_tDeliveryState_Delivered"]],
                      [
                        ["wos_work_phase_state", "=", ["g.wo_sState_Finished"]]
                      ],
                      "else",
                      [
                        ["wos_work_phase_state", "=", ""]
                      ]
                    ],
                    ["_tbl_WRITE_STATE", ["wos_tbl", "true"]],
                    ["_rec_LOCKED_WAIT", ["wos_tbl", "true"]],
                    [
                      "if", ["OK", "=", "1"],
                      [
                        ["_por_rWosQuantity", "=", ["por_MaterialAmountToWorkQuantit", ["por_delivered_amount"]]],
                        [
                          "if", ["por_type", "=", ["g.po_tType_SubContract"]],
                          [
                            ["IDLE"]
                          ],
                          "elseif", ["_por_rWosQuantity", "=", "0"],
                          [
                            [
                              "if", ["por_delivery_state", "=", ["g.por_tDeliveryState_Delivered"]],
                              [
                                ["_por_rWosQuantity", "=", ["_fld_ValueReal", ["wos_remaining_amount"]]]
                              ],
                              "elseif", ["por_delivery_state", "=", ["g.por_tDeliveryState_PartialDeliv"]],
                              [
                                [
                                  "if", ["por_order_amount", "<>", "0"],
                                  [
                                    ["por_order_amount", "=", ["por_delivered_amount", "/", "por_order_amount"]],
                                    ["_por_rWosQuantity", "=", ["wos_remaining_amount", "*", "por_order_amount"]],
                                    ["_por_rWosQuantity", "=", ["Round", ["_por_rWosQuantity", "0"]]]
                                  ]
                                ]
                              ]
                            ]
                          ]
                        ],
                        [
                          "if", ["por_delivery_state", "=", ["g.por_tDeliveryState_Delivered"]],
                          [
                            ["_por_rWosRemainingQuantity", "=", "0"],
                            [
                              "if", ["por_type", "=", ["g.po_tType_SubContract"]],
                              [
                                [
                                  "if", ["_por_rWosQuantity", "<", ["wos_remaining_amount"]],
                                  [
                                    ["_por_rWosRemainingQuantity", "=", ["wos_remaining_amount", "-", "_por_rWosQuantity"]],
                                    ["_por_tWosPhaseState", "=", ["g.wo_sState_Started"]]
                                  ]
                                ]
                              ]
                            ]
                          ],
                          "else",
                          [
                            ["_por_rWosRemainingQuantity", "=", ["wos_remaining_amount", "-", "_por_rWosQuantity"]],
                            [
                              "if", ["_por_rWosRemainingQuantity", "<=", "0"],
                              [
                                ["_por_rWosRemainingQuantity", "=", "0"]
                              ]
                            ]
                          ]
                        ],
                        ["_fld_VALUE_REAL_SET", ["set", "wos_produced_amount", ["wos_produced_amount", "+", "_por_rWosQuantity"]]],
                        ["_fld_VALUE_REAL_SET", ["set", "wos_remaining_amount", "_por_rWosRemainingQuantity"]],
                        ["_fld_VALUE_STR_SET", ["set", "wos_work_phase_state", "wos_work_phase_state"]],
                        [
                          "if", [["por_type", "=", ["g.po_tType_Material"]], "and", ["_por_lFirstPhaseUpdate", "=", "false"]],
                          [
                            [
                              "if", [["wos_work_phase_state", "=", ["g.wo_sState_Loaded"]], "or", ["wos_work_phase_state", "=", ["g.wo_sState_NotLoaded"]]],
                              [
                                ["_fld_VALUE_STR_SET", ["set", "wos_work_phase_state", "g.wo_sState_Started"]]
                              ]
                            ]
                          ]
                        ],
                        ["_rec_SAVE", ["wos_tbl"]],
                        [
                          "if", ["OK", "=", "0"],
                          [
                            ["_por_rWosQuantity", "=", "1"]
                          ],
                          "else",
                          [
                            ["wos_STATE_CHANGE ---- ??, menee liian syvälle"],
                            ["wo_FAILED_AND_REMAINING_SET ---- ??, menee liian syvälle", ["_por_tProductionLot"]]
                          ]
                        ]
                      ],
                      ["_tbl_WRITE_STATE", ["wos_tbl", "previous"]]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ],
      ["ret", "=", ["_por_rWosQuantity"]]
    ],
    "por_MaterialAmountToWorkQuantit": [
      ["_por_rAmount", "=", ["arg1"]],
      ["_por_tType", "=", ["_fld_ValueStr", ["por_type"]]],
      [
        "if", ["_por_tType", "=", ["g.po_tType_SubContract"]],
        [
          ["IDLE"]
        ],
        "else",
        [
          ["_por_tProduct", "=", ["_fld_ValueStr", ["por_product_id"]]],
          ["_por_tWork", "=", ["_fld_ValueStr", ["por_work_position_number_id"]]],
          ["_por_rAmount", "=", ["w__MaterialAmountToWorkQuantity", ["_por_tProduct", "_por_rAmount", "_por_tWork"]]]
        ]
      ],
      ["ret", "=", ["_por_rAmount"]]
    ],
    "por_TILATTU_MRA": [
      ["por_scTILATTU_MAAR"],
      [
        "if", ["!aaOptionKey"],
        [
          ["stpa_S_KPL_MITTA", ["por_product_id", "por_dimension", "por_unit_total", "por_order_amount", "por_order_amount_2"]]
        ]
      ],
      ["por_wo_update", ["por_order_amount", "true", ""]]
    ],
    "por_scTILATTU_MAAR": [
      ["por_scMAARA_YKS1", ["por_production_id", "por_order_amount_2", "por_order_amount"]],
      ["por_L_RIVISUMMAT"],
      ["por_STOCK_ALARM"]
    ],
    "por_scRIVINUMERO": [
      ["por_order_row", "=", ["vaC_ValEraVaihe", ["por_purchase_order_id", "por_row_number", "por_partial_delivery_number"]]]
    ],
    "por_scENS_TOIM_PV": [
      [
        "if", ["por_confirmed_arrival_date", "<>", "00.00.0000"],
        [
          ["_por_tSetName", "=", ["g.por_Confirmed_set"]],
          ["_set_EMPTY_CREATE", ["por_tbl", "_por_tSetName"]],
          ["_por_tProcessName", ["_lang_Current", ["Check_confirmation_old_value"]]],
          ["_por_lPrsID", "=", ["New_process", ["por_CONFIRMATION_CHECK_PRS", "_prs_kMemStack", "_por_tProcessName", "por_record_id", "_por_tSetName"]]],
          [
            "if", ["false"],
            [
              ["por_CONFIRMATION_CHECK_PRS"]
            ]
          ],
          ["_prs__ANOTHER_PRS_CLOSE_WAIT", ["_por_lPrsID", "false"]],
          [
            "if", [["_set_RecsInSet", ["por_tbl", "_por_tSetName"]], "<=", "0"],
            [
              ["_fld_VALUE_STR_SET", ["set", "por_first_confirm_deliv_date", "_por_dConfirmed"]]
            ],
            "elseif", [["_fld_ValueDate", ["por_first_confirm_deliv_date"]], "=", "00.00.0000"],
            [
              ["_fld_VALUE_STR_SET", ["set", "por_first_confirm_deliv_date", "_por_dConfirmed"]]
            ],
            "else",
            [
              ["IDLE"]
            ]
          ],
          ["_set_CLEAR", ["por_tbl", "_por_tSetName"]]
        ]
      ]
    ],
    "por_CONFIRMATION_CHECK_PRS": [
      ["_por_tRecId", "=", ["arg1"]],
      ["_por_tSetName", "=", ["arg2"]],
      ["_por_dDate", "=", "00.00.0000"],
      ["_qry_Fld", ["0", ["por_record_id", "=", ["_por_tRecId"]], "*", "false", "false"]],
      ["_qry_Fld", ["0", ["por_first_confirm_deliv_date", "<>", ["_por_dDate"]], "&", "false", "false"]],
      ["_set_CREATE", ["por_tbl", "_por_tSetName"]]
    ],
    "por_scAHINTA": [
      [
        "if", ["aaOptionKey"],
        [
          [
            "if", ["por_production_id", "<>", ""],
            [
              ["RELATE_ONE", ["por_production_id"]],
              ["_pr_fRO_State", "=", ["aaRO_State", ["pr_tbl", "false"]]],
              [
                "if", [["!Locked", ["product"]]],
                [
                  [
                    "if", [["cur__IsLandCurren", ["po_currency_id"]], "=", "1"],
                    [
                      ["pr_purchase_price_unit", "=", ["por_price_unit"]]
                    ],
                    "else",
                    [
                      ["pr_currency_id", "=", ["po_currency_id"]],
                      ["pr_foreign_purch_pr_unit", "=", ["por_price_unit"]]
                    ]
                  ],
                  ["_rec_SAVE", ["pr_tbl"]]
                ],
                "else",
                [
                  ["xCRY", ["Tuote_on_lukittuna. Hintapaivitysta_ei_voi_tehda."]]
                ]
              ],
              ["aaRO_STATE_SET", ["pr_tbl", "_pr_fRO_State"]]
            ]
          ]
        ]
      ],
      ["por_L_RIVISUMMAT"],
      ["por_PRODUCT_PRICE_UPDATE"]
    ],
    "por_scOSTOKOODI": [
      [
        "if", ["poc_purchase_order_code", "<>", ["por_purchase_order_code_id"]],
        [
          ["RELATE_ONE", ["por_purchase_order_code_id"]]
        ]
      ],
      ["por_vat_percentage", "=", ["poc_vat_percentage"]],
      [
        "if", ["por_cost_center", "=", ""],
        [
          ["por_cost_center", "=", ["poc_target"]]
        ]
      ],
      ["xpRealFile", "=", ["po"]],
      ["por_L_RIVISUMMAT"]
    ],
    "por_scLVV_PROSENTT": [
      [
        "if", ["por_vat_percentage", "<>", ["poc_vat_percentage"]],
        [
          ["xCRY", ["Ostokoodin_lvv % ei_vastaa_syotettya_prosenttia."]]
        ]
      ],
      ["por_L_RIVISUMMAT"]
    ],
    "por_scTOIMITETTU_Y": [
      ["_por_lOK", "=", "true"],
      ["_fii_UPDATE_START", ["por_tbl"]],
      ["_rJaljella", "=", ["por_order_amount", "-", "por_delivered_amount"]],
      [
        "if", ["por_delivered_amount", "<>", "0"],
        [
          [
            "if", ["_fii_TblScripRunOutside", "=", "true"],
            [
              [
                "if", ["_rJaljella", ">", "0"],
                [
                  ["_win_DIALOG", ["0", "D_Osatoimitus", ["_lang_Current", ["Delivery"]]]],
                  [
                    "if", ["OK", "=", "1"],
                    [
                      [
                        "if", ["_dlg_lrbOsatoimitus", "=", "1"],
                        [
                          [
                            "if", ["_fii_InUse", "=", "false"],
                            [
                              ["_por_lOK", "=", "false"],
                              ["_err_MESSAGE", [["_lang_Current", ["Partial_delivery_can_not_be_done_within_row_modification"]], "Current_method_name", "true"]]
                            ],
                            "else",
                            [
                              [
                                "if", ["por_partial_delivery_number", "=", "0"],
                                [
                                  ["por_partial_delivery_number", "=", "1"],
                                  ["_txt", "=", ["_fld_ValueStr", ["por"]]],
                                  [
                                    "if", ["_txt", "<>", ""],
                                    [
                                      [
                                        "if", [["_qry_Fld", ["stpa_tbl", ["stpa_order_row", "=", ["_txt"]], "", "false"]], ">", "0"],
                                        [
                                          ["_txt", "=", ["vaC_ValEraVaihe", ["por_purchase_order_id", "por_row_number", "por_partial_delivery_number"]]],
                                          ["_sel_APPLY_TO_SEL", ["stpa_order_row", "_txt", "false"]]
                                        ]
                                      ]
                                    ]
                                  ]
                                ]
                              ],
                              ["por_order_row", "=", ["vaC_ValEraVaihe", ["por_purchase_order_id", "por_row_number", "por_partial_delivery_number"]]],
                              ["_iAlaera", "=", ["por_partial_delivery_number"]],
                              ["por_date_of_arrival", "=", ["Current_date", ["*"]]],
                              ["por_delivery_state", "=", "OT"],
                              ["por_L_RIVISUMMAT"],
                              ["_rec_SAVE", ["por_tbl"]],
                              ["_por_lRow", ["_fii_SelectedRecordRowGet", ["por_tbl"]]],
                              [
                                "if", ["_por_lRow", "<", "1"],
                                [
                                  ["_err_MESSAGE", [["_lang_Current", ["Record_number_was_not_found"]], "por_scTOIMITETTU_Y", "true"]]
                                ],
                                "else",
                                [
                                  ["_fii_ROW_ADD", ["before", "por_tbl", "0"]],
                                  ["_rec_DUPLICATE", ["por_tbl"]],
                                  ["por_order_amount", "=", ["por_order_amount", "-", "por_delivered_amount"]],
                                  ["por_scMAARA_YKS1", ["por_product_id", "por_order_amount_2", "por_order_amount"]],
                                  ["por_delivered_amount", "=", "0"],
                                  ["por_partial_delivery_number", "=", ["_iAlaera", "+", "1"]],
                                  ["por_order_row", "=", ["vaC_ValEraVaihe", ["por_purchase_order_id", "por_row_number", "por_partial_delivery_number"]]],
                                  ["por_delivery_state", "=", ""],
                                  ["por_stock_event", "=", ""],
                                  ["por_date_of_arrival", "=", "00.00.0000"],
                                  ["_rec_SAVE", ["por_tbl"]],
                                  ["por_L_RIVISUMMAT"],
                                  ["_rec_SAVE", ["por_tbl"]],
                                  ["_fii_ROW_ADD", ["after", "por_tbl", ["_por_lROW", "+", "1"]]],
                                  ["_fii__ROW_GOTO", ["por_tbl", "_por_lRow"]]
                                ]
                              ]
                            ]
                          ]
                        ],
                        "else",
                        [
                          ["por_date_of_arrival", "=", ["Current_date", ["*"]]],
                          [
                            "if", ["por_confirmed_arrival_date", "=", "00.00.0000"],
                            [
                              ["por_confirmed_arrival_date", "=", ["Current_date", ["*"]]]
                            ]
                          ],
                          ["por_delivery_state", "=", "LT"],
                          ["por_L_RIVISUMMAT"]
                        ]
                      ]
                    ],
                    "else",
                    [
                      ["_por_lOK", "=", "false"],
                      ["por_delivered_amount", "=", "0"],
                      ["GOTO_OBJECT", ["por_delivered_amount"]]
                    ]
                  ]
                ],
                "else",
                [
                  [
                    "if", ["por_delivery_state", "<>", ""],
                    [
                      ["DIALOG", ["D_Loppuuntoimit"]]
                    ],
                    "else",
                    [
                      ["_dlg_lrbOsatoimitus", "=", "0"],
                      ["OK", "=", "1"]
                    ]
                  ],
                  [
                    "if", ["OK", "=", "1"],
                    [
                      ["por_date_of_arrival", "=", ["Current_date", ["*"]]],
                      [
                        "if", ["por_confirmed_arrival_date", "=", "00.00.0000"],
                        [
                          ["por_confirmed_arrival_date", "=", ["Current_date", ["*"]]]
                        ]
                      ],
                      [
                        "if", ["_dlg_lrbOsatoimitus", "=", "1"],
                        [
                          ["por_delivery_state", "=", "OT"]
                        ],
                        "else",
                        [
                          ["por_delivery_state", "=", "LT"]
                        ]
                      ]
                    ],
                    "else",
                    [
                      ["_por_lOK", "=", "false"],
                      ["por_delivered_amount", "=", "0"],
                      ["GOTO_OBJECT", ["por_delivered_amount"]]
                    ]
                  ]
                ]
              ]
            ],
            "else",
            [
              ["_por_lOK", "=", "false"]
            ]
          ]
        ],
        "else",
        [
          ["por_delivery_state", "=", ""],
          ["por_date_of_arrival", "=", "00.00.0000"]
        ]
      ],
      [
        "if", ["_por_lOK", "=", "true"],
        [
          ["por_WO_UPDATE", ["por_delivered_amount", "true", ""]],
          ["por_WOS_UPDATE"],
          ["por_WOS_FIRST_PHASE_UPDATE", ["true"]]
        ]
      ],
      ["_fii_UPDATE_END", ["por_tbl"]]
    ],
    "por_L_RIVISUMMAT": [
      ["por_L_RIVIT"]
    ],
    "por_L_RIVIT": [
      [
        "if", ["por_delivered_amount", "<=", "0"],
        [
          ["por_purchase_price_total", "=", ["por_price_unit", "*", "por_order_amount"]]
        ],
        "else",
        [
          ["por_purchase_price_total", "=", ["por_price_unit", "*", "por_delivered_amount"]]
        ]
      ],
      ["por_purchase_price_total", "=", ["Round", ["por_purchase_price_total", "2"]]],
      [
        "if", ["por_discount_percentage", "<>", "0"],
        [
          ["por_discount_amount", "=", ["Round", [[["por_purchase_price_total", "*", "por_discount_percentage"], "/", "100"], "2"]]],
          ["por_purchase_price_total", "=", ["por_purchase_price_total", "-", "por_discount_amount"]]
        ],
        "else",
        [
          ["por_discount_amount", "=", "0"]
        ]
      ],
      ["por_vat_price", "=", ["Round", [[["por_vat_percentage", "*", "por_purchase_price_total"], "/", "100"], "2"]]],
      ["por_rostohint", "=", ["Round", [["aal_mk_lvvmk", ["por_purchase_price_total", "por_vat_percentage"]], "2"]]]
    ],
    "por_ALE_L_RIVISUM": [
      [
        "if", ["por_delivered_amount", "<=", "0"],
        [
          ["por_purchase_price_total", "=", ["por_price_unit", "*", "por_order_amount", "-", "por_discount_amount"]],
          [
            "if", ["por_discount_amount", "<>", "0"],
            [
              ["por_discount_percentage", "=", [[["Round", ["por_dicount_amount", "/", "por_price_unit", "*", "por_order_amount"], "*", "100"], "2"]]]
            ],
            "else",
            [
              ["por_discount_percentage", "=", "0"]
            ]
          ]
        ],
        "else",
        ["por_purchase_price_total", "=", ["por_price_unit", "*", "por_delivered_amount", "-", "por_discount_amount"]],
        [
          "if", ["por_discount_amount", "<>", "0"],
          [
            ["por_discount_percentage", "=", [[["Round", ["por_discount_amount", "/", "por_price_unit", "*", "por_delivered_amount"], "*", "100"], "2"]]]
          ]
        ],
        "else",
        [
          ["por_discount_percentage", "=", "0"]
        ]
      ],
      ["por_purchase_price_total", "=", ["round", ["por_purchase_price_total", "2"]]],
      ["por_vat_price", "=", [[["round", ["por_vat_percentage", "*", "por_purchase_price_total"], "/", "100"], "2"]]],
      ["por_ostohint", "=", ["round", [["aal_mk_lvvmk", ["por_purchase_price_total", "por_vat_percentage"]], "2"]]],
      [
        "if", ["xpRealFile", "=", ["po"]],
        [
          ["po_L_ALAR_KENTAT ---- ??, menee liian syvälle"]
        ]
      ]
    ],
    "por_sc1_VAH_TO_PV": [
      [
        "if", ["_fld_ValueDate", ["por_first_confirm_deliv_date"], "<>", "00.00.0000"],
        [
          ["_fld_VALUE_LONG_SET", ["set", "por_confirmation_state", "1"]]
        ]
      ]
    ],
    "por_PRODUCT_PRICE_UPDATE": [
      [
        "if", ["g.por_lUpdatePricesToProduct", "<>", "0"],
        [
          [
            "if", ["_el_InInput", "=", "true"],
            [
              [
                "if", ["por_delivery_state", "<>", ""],
                [
                  ["_por_lOK", "=", "true"]
                ],
                "elseif", [["por_delivery_state", "=", ""], "and", ["g.por_lUpdatePricesToProduct", "<", "0"]],
                [
                  ["_por_lOK", "=", "false"]
                ],
                "else",
                [
                  ["_por_lOK", "=", "false"]
                ]
              ],
              [
                "if", ["_por_lOK", "=", "true"],
                [
                  [
                    "if", [["por_product_id", "<>", ""], "and", ["por_price_unit", ">", "0"]],
                    [
                      [
                        "if", [["Abs", ["g.por_lUpdatePricesToProduct"]], "=", "1"],
                        [
                          ["_por_lOK", "=", ["_info__Confirm", ["_lang_Current", ["Save_purchase_price_to_product?"]]]],
                          [
                            "if", ["_por_lOK", "=", "yes"],
                            [
                              ["_por_lOK", "=", "true"]
                            ],
                            "else",
                            [
                              ["_por_lOK", "=", ["false"]]
                            ]
                          ]
                        ],
                        "else",
                        [
                          ["_por_lOK", "=", "true"]
                        ]
                      ],
                      [
                        "if", ["_por_lOK", "=", "true"],
                        [
                          [
                            "if", ["por_delivery_state", "=", ""],
                            [
                              ["_por_rDeliveredAmount", "=", ["_fld_ValueReal", ["por_order_amount"]]]
                            ],
                            "else",
                            [
                              ["_por_rDeliveredAmount", "=", ["_fld_ValueReal", ["por_delivered_amount"]]]
                            ]
                          ],
                          ["po_PRODUCT_PRICE_UPDATE ---- ??, menee liian syvälle", ["por_price_unit", "por_purchase_costs", "_por_rDeliveredAmount"]]
                        ]
                      ]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]
  }
}
