{
  "info": "",
  "field": {
    "sor": [
      ["sor_scBEFORE"]
    ],
    "sor_sales_order_id": [],
    "sor_product_id": [
      ["sor_scTUOTE_2"],
      ["sor_DATE_CHECK", ["add", "arg1"]]
    ],
    "sor_sales_order_code_id": [
      ["sor_scMYYNTIKOODI"]
    ],
    "sor_discount_percentage": [
      ["sor_ALEPROSENTTI"]
    ],
    "sor_discount_amount": [
      ["sor_ALENNUS_MK"]
    ],
    "sor_delivered_date": [
      ["sor_scTOIMITUSPAI"],
      ["so_EDI_CONFIRMATION_INFO_CHANGE ----<>"],
      ["sor_DATE_CHECK", ["add", "arg1"]]
    ],
    "sor_ordered_amount": [
      ["sor_scMAARA_YKS1"],
      ["so_EDI_CONFIRMATION_INFO_CHANGE ----<>"],
      ["stpa_S_KPL_MITTA", ["sor_product_id", "sor_packet_length", "sor_units_packet", "sor_ordered_amount", "sor_rTil_y2"]],
      ["sor_DATE_CHECK", ["add", "arg1"]]
    ],
    "sor_cost_price_total": [
      ["sor_scOMAKUSTANNUS"]
    ],
    "sor_price_unit": [
      ["sor_scAHINTA_YKS1"]
    ],
    "sor_delivered_quantity": [
      ["sor_scDELIVERED_QUANTITY"]
    ],
    "sor_waiting_for_delivery": [],
    "sor_dispatch_note_id": [],
    "sor_stock_event": [],
    "sor_invoice_id": [
      [
        "if", ["sor_invoice_id", "=", ["_lang_Current", ["No_invoice"]]],
        [
          ["IDLE"]
        ]
      ]
    ],
    "sor_row_number": [],
    "sor_partial_delivery_number": [],
    "sor_sales_price_total": [
      ["sor_scMYYNTIHINTA_"]
    ],
    "sor_unit": [],
    "sor_customer_row_number": [],
    "sor_info": [],
    "sor_customer_row_number": [],
    "sor_info": [],
    "sor_delivery_state": [],
    "sor_calc_sales_price_total": [],
    "sor_vat_percentage": [],
    "sor_explanation": [],
    "sor_vat_price": [],
    "sor_delivered_before": [],
    "sor_type": [],
    "sor_serial_number": [],
    "sor_in_dispatch_note": [],
    "sor_number_of_packets": [
      ["sor_scPAK_LKM"]
    ],
    "sor_remove_from_stock": [],
    "sor_no_printing": [],
    "sor_parcel_code": [
      ["sor_scVARASTOPAIKK"],
      [
        "if", ["false"],
        [
          ["stpa_rKokMaara", "=", "sor_waiting_for_delivery"],
          [
            "if", ["stpa_rKokMaara", "<", "0"],
            [
              ["stpa_rKokMaara", "=", "0"]
            ]
          ],
          ["stpa_sInfo", "=", ["concat", ["so_company_id", " / Tuote: ", "sor_product_id", " - avoinna: ", ["String", ["stpa_rKokMaara", "###,###,##0.##"]], " ", "sor_unit"]]],
          ["stpa_HAE_MITTA_KPL", ["sor_product_id", "sor_parcel_code", "sor_packet_length", "sor_units_packet", "g.gpNIL2", "g.gpNIL2"]],
          [
            "if", [[["Records_in_selection", ["Stock_Parcel"]], "=", "0"], "and", ["sor_parcel_code", "<>", ""]],
            [
              ["CONFIRM", ["Pakettia_ei_loytynyt. Yritatko_uudestaan?"]],
              [
                "if", ["OK", "=", "1"],
                [
                  ["sor_parcel_code", "=", ""]
                ]
              ]
            ]
          ]
        ]
      ],
      ["stpa_HAE_MITTA_KPL", ["sor_product_id", "sor_parcel_code", "sor_packet_length", "sor_units_packet", "g.gpNIL2", "g.gpNIL2"]]
    ],
    "sor_make_invoice": [],
    "sor_confirmed_delivery_date": [
      ["sor_scVAHV_TOI_PV"],
      ["so_EDI_CONFIRMATION_INFO_CHANGE ----<>"],
      ["sor_DATE_CHECK", ["add", "arg1"]]
    ],
    "sor_delivery_date": [],
    "sor_tariff_heading": [],
    "sor_pallet_number": [],
    "sor_order_state": [],
    "sor_work_phase_number": [],
    "sor_position": [],
    "sor_production_lot": [],
    "sor_material_est_arrival_date": [],
    "sor_commision_unit": [],
    "sor_marketing_support_unit": [],
    "sor_commission_percent": [],
    "sor_marketing_support_percent": [],
    "sor_commission": [],
    "sor_marketing_support": [],
    "sor_material_act_arrival_date": [],
    "sor_delivery_time": [],
    "sor_in_enclosure": [],
    "sor_packet_length": [
      ["sor_KPL_MAARA"],
      ["sor_scPITUUS"]
    ],
    "sor_units_packet": [
      ["sor_KPL_MAARA"]
    ],
    "sor_first_conf_delivery_date": [
      ["sor_sc1_VAH_TO_PV"]
    ],
    "sor_production_state": [],
    "sor_units_x_packet": [
      ["sor_scKPL_X_PAK"]
    ],
    "sor_units_y_packet": [
      ["sor_scKPL_Y_PAK"]
    ],
    "sor_volume": [
      ["sor_scTILAVUUS"]
    ],
    "sor_order_amount_2": [
      ["sor_scMAARA_YKS2"],
      ["sor_DATE_CHECK", ["add", "arg1"]]
    ],
    "sor_unit_2": [
      ["sor_scAHINTA_YKS2"]
    ],
    "sor_unit_price_volume": [
      ["sor_scAHINTA_TILAV"]
    ],
    "sor_price_with_vat_unit": [
      ["sor_scAHINTA_ALV"]
    ],
    "sor_amount_to_collect": [],
    "sor_collected_amount": [],
    "sor_price_group": [
      ["sor_scPRICE_GROUP"]
    ],
    "sor_record_id": [],
    "sor_firm_id": [],
    "sor_purchase_order_row": [],
    "sor_cost_center": [],
    "sor_transfer_id": [],
    "sor_est_manufacture_date": [],
    "sor_est_manufacture_time": [],
    "sor_critical_start_date": [],
    "sor_critical_start_time": [],
    "sor_waybill_id": [
      [
        "if", ["sor_waybill_id", "=", ["_lang_Current", ["No_waybill"]]],
        [
          ["IDLE"]
        ]
      ]
    ],
    "sor_project_id": [],
    "sor_critical_start_difference": [],
    "sor_est_finish_difference": [],
    "sor_need_calculation_type": [],
    "sor_change_id": [],
    "sor_creator_id": [],
    "sor_modifier_id": [],
    "sor_transfer_state": [],
    "sor_sales_margin_percentage": [],
    "sor_sales_margin": [],
    "sor_material_cost": [],
    "sor_material_margin_percentage": [],
    "sor_material_margin": [],
    "sor_additional_data": [],
    "sor_pricing_state": [
      ["sor_scPRICING_STATE"]
    ],
    "sor_postcalc_date": [],
    "sor_sales_probability": []
  },
  "function": {
    "sor_scBEFORE": [
      ["sor_sales_order_id", "=", ["so_sales_order_id"]],
      ["sor_row_number", "=", [["max", ["sor_row_number"]], "+", "1"]],
      ["sor_customer_row_number", "=", ["string", ["sor_row_number", "|mreratunnus"]]],
      [
        "if", ["g.so_lDefaultDeliveryDays", "<>", "0"],
        [
          ["sor_delivered_date", "=", [["_date_Current", ["true"]], "+", "g.so_lDefaultDeliveryDays"]]
        ],
        "else",
        [
          ["sor_delivered_date", "=", ["so_first_delivery_date"]]
        ]
      ],
      ["sor_scTOIMITUSPAI"],
      ["sor_ordered_amount", "=", "1"],
      ["sor_waiting_for_delivery", "=", ["sor_ordered_amount"]],
      ["sor_type", "=", ["so_type"]],
      ["sor_order_state", "=", ["so_state"]],
      ["sor_number_of_packets", "=", "1"]
    ],
    "sor_scTUOTE_2": [
      [
        "if", ["pr_not_in_use"],
        [
          ["_err_CRY", ["Tama_tuote_on_merkitty_kaytosta_poistetuksi.", "true"]]
        ]
      ],
      [
        "if", ["g.sor_lCopyQualityToSerialNumber", "=", "true"],
        [
          ["sor_serial_number", "=", ["pr_quality"]]
        ]
      ],
      ["sor_unit", "=", ["pr_unit"]],
      ["sor_unit_2", "=", ["pr_unit_2"]],
      ["sor_tariff_heading", "=", ["pr_tariff_heading"]],
      ["sor_parcel_code", "=", ["pr_parcel_code"]],
      [
        "if", ["pr_no_discount"],
        [
          ["sor_discount_percentage", "=", "0"]
        ],
        "else",
        [
          [
            "if", ["g.so_lRowDiscountCustomer", "=", "2"],
            [
              [
                "if", ["so_invoicing_company_id", "<>", ["co_company_id"]],
                [
                  ["_sel_RELATE_ONE", ["co_company_id", "so_invoicing_company_id"]]
                ]
              ]
            ],
            "elseif", ["g.so_lRowDiscountCustomer", "=", "1"],
            [
              [
                "if", ["so_delivery_company_id", "<>", ["co_company_id"]],
                [
                  ["_sel_RELATE_ONE", ["co_company_id", "so_delivery_company_id"]]
                ]
              ]
            ],
            "else",
            [
              [
                "if", ["so_company_id", "<>", ["co_company_id"]],
                [
                  ["_sel_RELATE_ONE", ["co_company_id", "so_company_id"]]
                ]
              ]
            ]
          ],
          [
            "if", ["co_row_discount_percentage", "<>", "0"],
            [
              ["sor_discount_percentage", "=", ["co_row_discount_percentage"]]
            ]
          ],
          [
            "if", ["so_company_id", "<>", ["co_company_id"]],
            [
              ["_sel_RELATE_ONE", ["co_company_id", "so_company_id"]]
            ]
          ]
        ]
      ],
      ["sor_C_MAARAT", ["sor_ordered_amount"]],
      ["sor_C_MKOOD_HINTA"],
      ["sor_C_aHINNAT", ["sor_price_unit"]],
      [
        "if", ["pr_work_position_num_id", "<>", ""],
        [
          [
            "if", ["pr_work_position_num_id", "<>", ["w_work_position_num_id"]],
            [
              ["RELATE_ONE", ["pr_work_position_num_id"]]
            ]
          ],
          ["sor_position", "=", ["w_position"]]
        ],
        "else",
        [
          ["sor_position", "=", ""]
        ]
      ],
      ["_sor_tExplanation", "=", ""],
      [
        "if", [["co_language", "<>", "Suomi"], "and", ["co_language", "<>", ""], "and", ["g.gfKielinimi"]],
        [
          ["QUERY", ["pn", ["pn_name_id", "=", ["sor_product_id"]], "*"]],
          ["QUERY", ["pn", "&", ["pn_language", "=", ["co_language"]]]],
          [
            "if", [["Records_in_selection", ["pn"]], ">", "0"],
            [
              ["_sor_tExplanation", "=", ["pn_name"]],
              ["sor_unit", "=", ["pn_unit"]]
            ],
            "else",
            [
              ["QUERY", ["pn", ["pn_product_name_id", "=", ["sor_product_id"]], "*"]],
              ["QUERY", ["pn", "&", ["pn_language", "=", ["Englanti"]]]],
              [
                "if", [["Records_in_selection", ["pn"]], ">", "0"],
                [
                  ["_sor_tExplanation", "=", ["pn_name"]],
                  ["sor_unit", "=", ["pn_unit"]]
                ],
                "else",
                [
                  ["_sor_tExplanation", "=", ["pr_name"]]
                ]
              ]
            ]
          ]
        ],
        "else",
        [
          ["_sor_tExplanation", "=", ["pr_name"]]
        ]
      ],
      ["sor_explanation", "=", ["_sor_tExplanation"]],
      [
        "if", ["g.pr_lSeliKopi", "=", "1"],
        [
          [
            "if", ["sor_explanation", "<>", ""],
            [
              ["sor_explanation", "=", ["concat", ["sor_explanation", "\n"]]]
            ]
          ],
          ["sor_explanation", "=", ["sor_explanation", "+", ["pr_explanation"]]]
        ],
        "elseif", ["g.pr_lSeliKopi", "=", "2"],
        [
          ["sor_explanation", "=", ["pr_explanation"]]
        ]
      ],
      ["sor_in_dispatch_note", "=", ["!pr_not_in_dispatch_note"]],
      ["sor_make_invoice", "=", ["!pr_no_billing"]],
      ["sor_remove_from_stock", "=", ["pr_storable"]],
      ["sor_no_printing", "=", ["pr_no_printing"]],
      ["sor_in_enclosure", "=", ["pr_is_in_eclosure"]],
      [
        "if", ["so_cost_center", "<>", ""],
        [
          ["sor_cost_center", "=", ["so_cost_center"]]
        ],
        "else",
        [
          ["sor_cost_center", "=", ["pr_cost_center"]]
        ]
      ],
      [
        "if", ["sor_cost_center", "=", ""],
        [
          ["sor_cost_center", "=", ["soc_cost_center"]]
        ]
      ],
      ["sor_L_RIVISUMMAT"],
      ["sor_STOCK_ALARM"]
    ],
    "sor_C_MKOOD_HINTA": [
      ["_sel_RELATE_ONE", ["co_company_id", "so_company_id"]],
      ["_sel_RELATE_ONE", ["pr_product_id", "sor_product_id"]],
      [
        "if", ["so_type", "=", "LA"],
        [
          ["sor_sales_order_code_id", "=", ["g.so_sLahjakoo"]]
        ],
        "else",
        [
          [
            "if", ["co_sales_order_code_id", "<>", ""],
            [
              ["sor_sales_order_code_id", "=", ["co_sales_order_code_id"]]
            ],
            "elseif", ["co_foreign_company"],
            [
              ["sor_sales_order_code_id", "=", ["pr_foreign_sales_ord_code_id"]]
            ],
            "else",
            [
              ["sor_sales_order_code_id", "=", ["pr_sales_order_code_id"]]
            ]
          ]
        ]
      ],
      ["sor_price__unit_set", ["sor_product_id"]],
      ["sor_sales_order_code_id", "=", ["soc__newcodeget", ["sor_sales_order_code_id"]]],
      ["_sel_RELATE_ONE", ["soc_sales_order_code_id", "sor_sales_order_code_id"]],
      ["sor_vat_percentage", "=", ["soc_vat_percentage"]],
      ["sor_commission_unit", "=", ["soc_commission_unit"]],
      ["sor_marketing_support_unit", "=", ["soc_marketing_support_unit"]],
      ["sor_commission_percent", "=", ["soc_commission_percent"]],
      ["sor_marketing_support_percent", "=", ["soc_marketing_support_percent"]]
    ],
    "sor_L_RIVISUMMAT": [
      ["sor_L_RIVIKENTAT"],
      ["sor_L_MUUTTUJAT"],
      [
        "if", [["_el_Tbl", "=", "so_rbl"], "and", ["_el_InInput", "=", "true"]],
        [
          ["so_C_ALAR_KENTAT ---- ??, ei ole sor_ -alkuinen"]
        ]
      ]
    ],
    "sor_L_RIVIKENTAT": [
      ["sor_C_LASK_MH_OK"],
      [
        "if", ["sor_discount_percentage", "<>", "0"],
        [
          ["sor_discount_amount", "=", ["Round", [[["sor_calc_sales_price_total", "*", "sor_discount_percentage"], "/", "100"], "2"]]]
        ],
        "else",
        [
          ["sor_discount_amount", "=", "0"]
        ]
      ],
      [
        "if", [["sor_type", "=", "TT"], "and", ["sor_number_of_packets", "<>", "0"], "or", ["sor_type", "=", "AH"]],
        [
          ["sor_cost_price_total", "=", "0"]
        ]
      ],
      ["sor_sales_price_total", "=", ["sor_calc_sales_price_total", "-", "sor_discount_amount"]],
      [
        "if", ["sor_price_with_vat_unit", "<>", "0"],
        [
          ["_so_rDiscountCreditWithVAT", "=", ["aaC_MK_LvvMK", ["sor_discount_amount", "sor_vat_percentage"]]],
          [
            "if", [["sor_delivered_quantity", "<>", "0"], "or", ["sor_delivery_state", "=", "OT"]],
            [
              ["_so_rSalesPriceWithVAT", "=", [["sor_price_with_vat_unit", "*", "sor_delivered_quantity"], "-", "_so_rDiscountCreditWithVAT"]]
            ],
            "else",
            [
              ["_so_rSalesPriceWithVAT", "=", [["sor_price_with_vat_unit", "*", "sor_waiting_for_delivery"], "-", "_so_rDiscountCreditWithVAT"]]
            ]
          ],
          [
            "if", ["g.inr_lRoundTotalPriceAndVAT", "=", "true"],
            [
              ["_so_rSalesPriceWithVAT", "=", ["Round", ["_so_rSalesPriceWithVAT", "2"]]]
            ]
          ],
          ["sor_vat_price", "=", ["_so_rSalesPriceWithVAT", "-", "sor_sales_price_total"]],
          ["sor_vat_price", "=", ["Round", ["sor_vat_price", "g.pr_iPyorAHin"]]]
        ],
        "else",
        [
          ["sor_vat_price", "=", [["sor_vat_percentage", "*", "sor_sales_price_total"], "/", "100"]],
          [
            "if", ["g.inr_lRoundTotalPriceAndVAT", "=", "true"],
            [
              ["sor_vat_price", "=", ["Round", ["sor_vat_price", "2"]]]
            ]
          ]
        ]
      ]
    ],
    "sor_C_LASK_MH_OK": [
      [
        "if", ["Count_parameters", ">=", "1"],
        [
          ["_pField", "=", ["arg1"]]
        ],
        "else",
        [
          ["_pField", "=", ["sor_price_unit"]]
        ]
      ],
      [
        "if", ["sor_product_id", "<>", "pr_product_id"],
        [
          ["RELATE_ONE", ["sor_product_id"]]
        ]
      ],
      [
        "if", ["_pField", "=", ["sor_unit_price_volume"]],
        [
          ["sor_calc_sales_price_total", "=", ["Round", [["sor_unit_price_volume", "*", "sor_volume"], "2"]]],
          [
            "if", ["sor_ordered_amount", "=", "0"],
            [
              ["sor_cost_price_total", "=", "0"]
            ],
            "elseif", ["sor_delivered_quantity", "<>", "0"],
            [
              ["sor_cost_price_total", "=", ["Round", [["pr_cost_price_unit", "*", "sor_delivered_quantity", "2"]]]]
            ],
            "else",
            [
              ["sor_cost_price_total", "=", ["Round", [["pr_cost_price_unit", "*", "sor_waiting_for_delivery"], "2"]]]
            ]
          ]
        ],
        "else",
        [
          [
            "if", ["sor_ordered_amount", "=", "0"],
            [
              ["sor_calc_sales_price_total", "=", "0"],
              ["sor_cost_price_total", "=", "0"]
            ],
            "elseif", [["sor_delivered_quantity", "<>", "0"], "or", ["sor_delivery_state", "=", "OT"]],
            [
              ["sor_calc_sales_price_total", "=", ["Round", [["sor_price_unit", "*", "sor_delivered_quantity"], "2"]]],
              ["sor_cost_price_total", "=", ["Round", [["pr_cost_price_unit", "*", "sor_delivered_quantity"], "2"]]]
            ],
            "else",
            [
              ["sor_calc_sales_price_total", "=", ["Round", [["sor_price_unit", "*", "sor_waiting_for_delivery"], "2"]]],
              ["sor_cost_price_total", "=", ["Round", [["pr_cost_price_unit", "*", "sor_waiting_for_delivery"], "2"]]]
            ]
          ]
        ]
      ],
      ["sor_sales_margin", "=", ["sor_sales_price_total", "-", "sor_cost_price_total"]],
      ["sor_sales_margin_percentage", "=", ["_real_percent", ["sor_sales_margin", "sor_sales_price_total", "0", "999", "0"]]]
    ],
    "sor_C_MAARAT": [
      ["_pField", "=", ["arg1"]],
      [
        "if", ["sor_product_id", "<>", ["pr_product_id"]],
        [
          ["RELATE_ONE", ["sor_product_id"]]
        ]
      ],
      [
        "if", ["_pField", "=", ["sor_volume"]],
        [
          [
            "if", ["sor_volume", "<>", "0"],
            [
              ["sor_unit_price_volume", "=", ["Round", [["sor_calc_sales_price_total", "/", "sor_volume"]], "g.pr_iPyorAHin"]]
            ]
          ]
        ],
        "else",
        [
          [
            "if", ["_pField", "=", ["sor_ordered_amount"]],
            [
              [
                "if", ["pr_conversion_multiplier", "<>", "0"],
                [
                  ["sor_order_amount_2", "=", ["pr_JaaVarMuutosk", ["sor_ordered_amount", "3"]]]
                ],
                "else",
                [
                  ["sor_order_amount_2", "=", "0"]
                ]
              ],
              ["sor_HAE_RA_TILAVU"]
            ],
            "elseif", ["_pField", "=", ["sor_ordered_amount_2"]],
            [
              ["sor_ordered_amount", "=", ["pr_KerVarMuutosk", ["sor_ordered_amount_2", "3"]]],
              ["sor_HAE_RA_TILAVU"]
            ]
          ],
          [
            "if", ["g.sor_lAllowPartialDeliveryChange", "=", "true"],
            [
              ["sor_waiting_for_delivery", "=", ["sor_ordered_amount", "-", "sor_delivered_before"]]
            ],
            "else",
            [
              ["sor_waiting_for_delivery", "=", ["sor_ordered_amount"]]
            ]
          ],
          ["_rAHinta", "=", ["sor_price_unit"]],
          ["sor_L_AHINTA", ["sor_price_unit", "true", "sor_ordered_amount"]],
          [
            "if", ["_rAHinta", "<>", ["sor_price_unit"]],
            [
            ]
          ],
          ["sor_L_RIVISUMMAT"],
          ["sor_C_aHINNAT", ["sor_price_unit"]],
          ["sor_STOCK_ALARM"]
        ]
      ]
    ],
    "sor_HAE_RA_TILAVU": [
      ["_rTilavuus", "=", "0"],
      [
        "if", ["sor_product_id", "<>", ["pr_product_id"]],
        [
          ["RELATE_ONE", ["sor_product_id"]]
        ]
      ],
      [
        "if", ["pr_work_position_num_id", "<>", ""],
        [
          ["QUERY", ["wme", ["wme_work_position_num_id", "=", ["pr_work_position_num_id"]]]],
          ["_j", "=", ["Records_in_selection", ["wme"]]],
          ["FIRST_RECORD", ["wme"]],
          [
            "for ---- ??", [["_i", "=", "1"], "_j"], "do",
            [
              ["RELATE_ONE", ["wme_raw_material_id"]],
              [
                "if", ["pr_design_unit", "=", "m3"],
                [
                  ["_rTilavuus", "=", ["_rTilavuus", "+", ["wme_quantity_unit", "*", "sor_ordered_amount"]]]
                ],
                "elseif", ["pr_design_unit_2", "=", "m3"],
                [
                  ["_rTilavuus", "=", ["_rTilavuus", "+", ["wme_quantity_unit_2", "*", "sor_ordered_amount"]]]
                ]
              ],
              ["NEXT_RECORD", ["wme"]]
            ]
          ]
        ]
      ],
      [
        "if", ["sor_product_id", "<>", ["pr_product_id"]],
        [
          ["RELATE_ONE", ["sor_product_id"]]
        ]
      ],
      [
        "if", ["_rTilavuus", "=", "0"],
        [
          ["sor_volume", "=", ["Round", [["pr_volume", "*", "sor_ordered_amount"], "3"]]]
        ],
        "else",
        [
          ["sor_volume", "=", ["Round", ["_rTilavuus", "3"]]]
        ]
      ]
    ],
    "sor_L_AHINTA": [
      ["_err_LANG_DO"],
      [
        "if", ["Count_parameters", ">=", "2"],
        [
          ["_fCry", "=", ["arg2"]]
        ],
        "else",
        [
          ["_fCry", "=", "true"]
        ]
      ],
      [
        "if", ["Count_parameters", ">=", "3"],
        [
          ["_sor_pChangedFld", "=", ["arg3"]]
        ],
        "else",
        [
          ["_sor_pChangedFld", "=", ["sor_price_group"]]
        ]
      ],
      [
        "if", ["so_type", "=", "LA"],
        [
          ["sor_price_unit", "=", ["arg1"]]
        ],
        "elseif", [["sor_type", "<>", "TT"], "and", ["sor_type", "<>", "AH"]],
        [
          [
            "if", ["g.so_lDefinePriceGroupCustomer", "=", "2"],
            [
              ["_sel_RELATE_ONE", ["co_company_id", "so_invoicing_company_id"]]
            ],
            "elseif", ["g.so_lDefinePriceGroupCustomer", "=", "1"],
            [
              ["_sel_RELATE_ONE", ["co_company_id", "so_delivery_company_id"]]
            ],
            "else",
            [
              ["_sel_RELATE_ONE", ["co_company_id", "so_company_id"]]
            ]
          ],
          [
            "if", [["g.gfHintaryhm"], "and", ["co_foreign_sales_price_in_use"]],
            [
              ["_sel_RELATE_ONE", ["pr_product_id", "sor_product_id"]],
              [
                "if", [["_sel_RecsInSel", ["pr_tbl"]], ">", "0"],
                [
                  [
                    "if", ["_sor_pChangedFld", "=", ["sor_price_group"]],
                    [
                      ["_sor_tPriceGroup", "=", ["sor_price_group"]]
                    ],
                    "elseif", ["_sor_pChangedFld", "=", ["sor_ordered_amount"]],
                    [
                      ["_sor_tPriceGroup", "=", ["co_price_group"]]
                    ],
                    "else",
                    [
                      ["_sor_tPriceGroup", "=", ["co_price_group"]]
                    ]
                  ],
                  ["_sor_lPriceGroupFound", "=", ["prpr__PriceGroupGet", ["sor_price_unit", "sor_discount_percentage", "sor_price_group", "_sor_tPriceGroup", "sor_product_id", "sor_ordered_amount", "so_currency_id"]]],
                  [
                    "if", ["_sor_lPriceGroupFound", "=", "false"],
                    [
                      ["sor_price_group", "=", ""],
                      [
                        "if", [["_sor_pChangedFld", "=", ["sor_price_group"]], "or", ["_sor_pChangedFld", "=", ["sor_ordered_amount"]]],
                        [
                          ["IDLE"]
                        ],
                        "else",
                        [
                          [
                            "if", ["so_currency_id", "=", ["cur__DefaultCurre"]],
                            [
                              ["sor_price_unit", "=", ["arg1"]]
                            ],
                            "else",
                            [
                              ["sor_price_unit", "=", "0"]
                            ]
                          ]
                        ]
                      ]
                    ]
                  ]
                ]
              ]
            ],
            "else",
            [
              ["sor_price_unit", "=", "arg1"]
            ]
          ]
        ],
        "else",
        [
          ["sor_discount_percentage", "=", "0"],
          ["sor_discount_amount", "=", "0"],
          ["sor_price_unit", "=", "0"],
          ["sor_sales_price_total", "=", "0"],
          ["sor_calc_sales_price_total", "=", "0"],
          ["sor_vat_percentage", "=", "0"],
          ["sor_vat_price", "=", "0"],
          [
            "if", ["sor_type", "=", ["AH"]],
            [
              ["sor_cost_price_total", "=", "0"]
            ]
          ]
        ]
      ]
    ],
    "sor_scMYYNTIKOODI": [
      ["RELATE_ONE", ["sor_sales_order_id"]],
      ["sor_vat_percentage", "=", ["soc_vat_percentage"]],
      ["sor_commision_unit", "=", ["soc_commission_unit"]],
      ["sor_marketing_support_unit", "=", ["soc_marketing_support_unit"]],
      ["sor_commission_percent", "=", ["soc_commission_percent"]],
      ["sor_marketing_support_percent", "=", ["soc_marketing_support_percent"]],
      ["sor_price_with_vat_unit", "=", ["Round", ["aac_mk_lvvmk", ["sor_price_unit", "sor_vat_percentage"], "g.pr_iPyorAHin"]]],
      ["xprealfile", "=", ["so"]],
      ["sor_L_RIVISUMMAT"],
      ["unload_record", ["soc"]]
    ],
    "sor_ALEPROSENTTI": [
      [
        "if", ["sor_discount_percentage", "<>", "0"],
        [
          ["sor_discount_amount", "=", [["sor_calc_sales_price_total", "*", "sor_discount_percentage"], "/", "100"]]
        ],
        "else",
        [
          ["sor_discount_amount", "=", "0"]
        ]
      ],
      ["sor_L_RIVISUMMAT"]
    ],
    "sor_ALENNUS_MK": [
      [
        "if", ["sor_calc_sales_price_total", "<>", "0"],
        [
          ["sor_discount_percentage", "=", [["sor_discount_amount", "/", "sor_calc_sales_price_total"], "*", "100"]]
        ],
        "else",
        [
          ["sor_discount_percentage", "=", "0"],
          ["sor_discount_amount", "=", "0"],
          ["xCRY", ["Laskennallinen_myyntihinta_on_nolla. Et_voi_antaa_alennusta."]]
        ]
      ],
      ["sor_L_RIVISUMMAT"]
    ],
    "sor_scTOIMITUSPAI": [
      ["sor_L_MUUTTUJAT"],
      [
        "if", ["g.sor_lSetConfirmedDeliveryDate", "=", "true"],
        [
          [
            "if", ["sor_confirmed_delivery_date", "=", "00.00.0000"],
            [
              ["sor_confirmed_delivery_date", "=", ["sor_delivered_date"]],
              ["sor_scVAHV_TOI_PV"]
            ]
          ]
        ]
      ],
      ["sor_STOCK_ALARM"]
    ],
    "sor_L_MUUTTUJAT": [
      ["sor_rrivisumm", "=", ["sor_sales_price_total", "+", "sor_vat_price"]],
      [
        "if", ["sor_product_id", "<>", ["pr_product_id"]],
        [
          ["_sel_RELATE_ONE", ["pr_product_id", "sor_product_id"]]
        ]
      ],
      [
        "if", ["pr_conversion_multiplier", "<>", "0"],
        [
          ["sor_rTil_y2", "=", ["Round", [["sor_ordered_amount", "/", "pr_conversion_multiplier"], "3"]]]
        ],
        "else",
        [
          ["sor_rTil_y2", "=", "0"]
        ]
      ],
      ["sor_rkate", "=", ["sor_sales_price_total", "-", "sor_cost_price_total"]],
      [
        "if", ["sor_sales_price_total", "<>", "0"],
        [
          ["sor_rKatePros", "=", [["sor_rKate", "/", "sor_sales_price_total"], "*", "100"]]
        ],
        "else",
        [
          ["sor_rKatePros", "=", "0"]
        ]
      ],
      ["sor_ltoimvko", "=", ["_date_toweek", ["sor_delivered_date"]]],
      ["sor_l1vatovko", "=", ["_date_toweek", ["sor_first_conf_delivery_date"]]],
      ["sor_lvahtovko", "=", ["_date_toweek", ["sor_confirmed_delivery_date"]]]
    ],
    "sor_STOCK_ALARM": [
      [
        "if", ["_el_InInput", "0", "true"],
        [
          [
            "if", [["_rec_Loaded", ["sor_tbl"]], "=", "false"],
            [
              ["_rec_LOAD", ["sor_tbl"]]
            ]
          ],
          [
            "if", [["sor_product_id", "<>", ["sor_tNeedProduct_id"]], "or", ["sor_ordered_amount", "<>", ["sor_rNeedOrderedAmount"]], "or", [["sor__DeliveryDate", ["false"]], "<>", ["sor_dNeedDeliveryDate"]]],
            [
              ["pr_nc__PRODUCT_STATE_INFO", ["_sor_tProduct_id", "_sor_rOrdered_Amount", "_sor_dDeliveryDate", "0", "false"]],
              ["sor_tNeedProduct_id", "=", ["sor_product_id"]],
              ["sor_rNeedOrderedAmount", "=", ["sor_ordered_amount"]],
              ["sor_dNeedDeliveryDate", "=", ["sor__DeliveryDate", ["false"]]]
            ],
            "else",
            [
              ["IDLE"]
            ]
          ]
        ]
      ]
    ],
    "so_EDI_CONFIRMATION_INFO_CHANGE ---- ??, ei ole sor_ -alkuinen": [],
    "sor_scMAARA_YKS1": [
      [
        "if", ["Count_parameters", ">=", "1"],
        [
          ["_fCry", "=", ["arg1"]]
        ],
        "else",
        [
          ["_fCry", "=", "true"]
        ]
      ],
      [
        "if", [["sor_delivery_state", "=", ""], "and", ["sor_partial_delivery_number", "=", "0"], "or", ["g.sor_lAllowPartialDeliveryChange", "=", "true"]],
        [
          ["sor_C_MAARAT", ["sor_ordered_amount"]],
          ["sor_wo_UPDATE"]
        ],
        "else",
        [
          [
            "if", ["_fCry"],
            [
              ["xCRY", ["Osa- ja_loppuntoimituksissa_ei_saa_muuttaa_tilattua_maaraa."]]
            ]
          ],
          ["sor_ordered_amount", "=", ["sor_delivered_before", "sor_delivered_quantity", "sor_waiting_for_delivery"]],
          ["GOTO_OBJECT", ["sor_ordered_amount"]]
        ]
      ]
    ],
    "sor_wo_UPDATE": [
      [
        "if", ["g.sor_lUpdateWorkOrderAmount", "=", "1"],
        [
          ["_sor_lOK", "=", ["_info__Confirm", ["_lang_Current", ["Do_you_want_to_update_ordered_amount_to_work_order?"]]]],
          [
            "if", ["_sor_lOK", "=", "yes"],
            [
              ["_sor_lOK", "=", "true"]
            ],
            "else",
            [
              ["_sor_lOK", "=", "false"]
            ]
          ]
        ],
        "elseif", ["g.sor_lUpdateWorkOrderAmount", "=", "2"],
        [
          ["_sor_lOK", "=", "true"]
        ],
        "else",
        [
          ["_sor_lOK", "=", "false"]
        ]
      ],
      [
        "if", ["_sor_lOK", "=", "true"],
        [
          [
            "if", ["sor_production_lot", "<>", ""],
            [
              ["_sel_RELATE_ONE", ["pr_product_id", "sor_product_id"]],
              ["COMPILER_pr"],
              [
                "if", [["_fld_ValueLong", ["pr_production_control_type"]], "=", ["g.pr_stlim_lProdCtrlType_Order"]],
                [
                  ["COMPILER_wo"],
                  ["_txt", "=", ["sor_production_lot"]],
                  ["_qry_Fld", ["0", ["wo_production_lot", "=", ["_txt"]], "", "false"]],
                  [
                    "if", [["_sel_RecsInSel", ["wo_tbl"]], ">", "0"],
                    [
                      [
                        "if", [["wo__IsOpenState", ["wo_state"]], "=", "true"],
                        [
                          [
                            "if", ["sor_ordered_amount", "<>", ["wo_started_amount"]],
                            [
                              ["_tbl_WRITE_STATE", ["wo_tbl", "true"]],
                              ["_rec_LOCKED_WAIT", ["wo_tbl", "true"]],
                              [
                                "if", ["OK", "=", "0"],
                                [
                                  ["_err_MESSAGE", ["concat", [["_lang_Current", ["Work_Order_was_locked"]], " (", "sor_production_lot", ")", "\n", ["_lang_Current", ["Sales_order_row_ordered_amount_was_not_saved_to_work_order"]], "Current_method_name", "false"]]]
                                ],
                                "else",
                                [
                                  ["_fld_VALUE_REAL_SET", ["set", "wo_started_amount", "sor_ordered_amount"]],
                                  ["xapp_TblRun", ["wo_started_amount", "wo_tbl", "noevent"]],
                                  ["_rec_SAVE", ["wo_tbl"]],
                                  [
                                    "if", ["OK", "=", "0"],
                                    [
                                      ["_err_MESSAGE", ["concat", [["_lang_Current", ["Work_Order_was_not_saved_because_of_unknown_error"]], " (", "sor_production_lot", ")", "\n", ["_lang_Current", ["Sales_order_row_ordered_amount_was_not_saved_to_work_order"]], "Current_method_name", "false"]]]
                                    ],
                                    "else",
                                    [
                                      ["_sel_RELATE_ONE", ["so_sales_order_id", "sor_sales_order_id"]],
                                      ["wo_WOS_VALUES_UPDATE ---- ??", ["sor_production_lot", "wo_work_position_num_id", "sor_ordered_amount", "so_company_id"]]
                                    ]
                                  ]
                                ]
                              ],
                              ["_tbl_WRITE_STATE", ["wo_tbl", "previous"]]
                            ]
                          ]
                        ]
                      ]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ],
    "sor_scOMAKUSTANNUS": [
      ["sor_L_MUUTTUJAT"],
      [
        "if", ["xpRealFile", "=", ["so"]],
        [
          ["so_C_ALAR_KENTAT ---- ??, ei ole sor_ -alkuinen"]
        ]
      ]
    ],
    "sor_scAHINTA_YKS1": [
      ["sor_C_aHINNAT", ["sor_price_unit"]]
    ],
    "sor_C_aHINNAT": [
      ["_pField", "=", ["arg1"]],
      [
        "if", ["sor_product_id", "<>", "pr_product_id"],
        [
          ["RELATE_ONE", ["sor_product_id"]]
        ]
      ],
      [
        "if", ["_pField", "=", ["sor_price_unit"]],
        [
          ["sor_price_unit_2", "=", ["pr_KerVarMuutosk", ["sor_price_unit", "g.pr_iPyorAHin"]]],
          ["sor_price_with_vat_unit", "=", ["Round", [["aaC_MK_LvvMK", ["sor_price_unit", "sor_vat_percentage"]], "g.pr_iPyorAHin"]]],
          [
            "if", ["sor_volume", "<>", "0"],
            [
              ["sor_C_LASK_MH_OK"],
              [
                "if", ["sor_volume", "<>", "0"],
                [
                  ["sor_unit_price_volume", "=", ["Round", [["sor_calc_sales_price_total", "/", "sor_volume"], "g.pr_iPyorAHin"]]]
                ],
                "else",
                [
                  ["sor_unit_price_volume", "=", "0"]
                ]
              ]
            ],
            "else",
            [
              ["sor_unit_price_volume", "=", "0"]
            ]
          ]
        ],
        "elseif", ["_pField", "=", ["sor_price_unit_2"]],
        [
          ["sor_price_unit", "=", ["pr_JaaVarMuutosk", ["sor_price_unit_2", "g.pr_iPyorAHin"]]],
          ["sor_price_with_vat_unit", "=", ["Round", [["aaC_MK_LvvMK", ["sor_price_unit", "sor_vat_percentage"]], "g.pr_iPyorAHin"]]],
          [
            "if", ["sor_volume", "<>", "0"],
            [
              ["sor_C_LASK_MH_OK"],
              ["sor_unit_price_volume", "=", ["Round", [["sor_calc_sales_price_total", "/", "sor_volume"], "g.pr_iPyorAHin"]]]
            ]
          ]
        ],
        "elseif", ["_pField", "=", ["sor_unit_price_volume"]],
        [
          ["sor_C_LASK_MH_OK", ["sor_unit_price_volume"]],
          [
            "if", ["sor_ordered_amount", "=", "0"],
            [
            ],
            "elseif", ["sor_delivered_quantity", "<>", "0"],
            [
              ["sor_price_unit", "=", ["Round", [["sor_calc_sales_price_total", "/", "sor_delivered_quantity"], "g.pr_iPyorAHin"]]]
            ],
            "else",
            [
              ["sor_price_unit", "=", ["Round", [["sor_calc_sales_price_total", "/", "sor_waiting_for_delivery"], "g.pr_iPyorAHin"]]]
            ]
          ],
          ["sor_price_unit_2", "=", ["pr_KerVarMuutosk", ["sor_price_unit", "g.pr_iPyorAHin"]]],
          ["sor_price_with_vat_unit", "=", ["Round", [["aaC_MK_LvvMK", ["sor_price_unit", "sor_vat_percentage"]], "g.pr_iPyorAHin"]]]
        ],
        "elseif", ["_pField", "=", ["sor_price_with_vat_unit"]],
        [
          ["sor_price_unit", "=", ["Round", ["aaC_LvvMK_MK", ["sor_price_with_vat_unit", "sor_vat_percentage"]], "g.pr_iPyorAHin"]],
          ["sor_price_unit_2", "=", ["pr_KerVarMuutosk", ["sor_price_unit", "g.pr_iPyorAHin"]]],
          [
            "if", ["sor_volume", "<>", "0"],
            [
              ["sor_C_LASK_MH_OK"],
              ["sor_unit_price_volume", "=", ["Round", [["sor_calc_sales_price_total", "/", "sor_volume"], "g.pr_iPyorAHin"]]]
            ]
          ]
        ]
      ],
      ["sor_L_RIVISUMMAT"],
      [
        "if", [["_fld_ValueLong", ["sor_kPricing_State"]], "=", "3"],
        [
          [
            "if", [["_el_Tbl", "=", "so_tbl"], "or", ["_el_Tbl", "=", ["sor_tbl"]]],
            [
              ["sor_scPRICING_STATE"]
            ]
          ]
        ]
      ]
    ],
    "sor_scDELIVERED_QUANTITY": [
      ["_fii_UPDATE_START", ["sor_tbl"]],
      [
        "if", [["sor_delivered_quantity", "=", "0"], "and", ["g.so_lPartialZeroDeliveryAllow", "=", "false"]],
        [
          ["sor_delivery_state", "=", ""],
          ["sor_delivery_date", "=", "00.00.0000"],
          ["sor_waiting_for_delivery", "=", ["sor_ordered_amount", "-", "sor_delivered_before", "-", "sor_delivered_quantity"]]
        ],
        "else",
        [
          [
            "if", ["_fii_TblScripRunOutside", "=", "true"],
            [
              ["_sor_rLeft", "=", ["Round", [["sor_ordered_amount", "-", "sor_delivered_before", "-", "sor_delivered_quantity"], "5"]]],
              [
                "if", ["sor_ordered_amount", "<", "0"],
                [
                  ["_sor_rLeft", "=", ["_sor_rLeft"]]
                ]
              ],
              [
                "if", [["_sor_rLeft", "<=", "0"], "and", ["g.so_lPartialZeroDeliveryAllow", "=", "false"]],
                [
                  ["_sor_lrbLeaveOpen", "=", "0"],
                  ["_sor_lrbPartialDelivery", "=", "0"],
                  ["_sor_lrbFinished", "=", "1"]
                ],
                "else",
                [
                  ["_win_DIALOG", ["0", "sor_D_AskPartialDelivery", ["_lang_Current", ["Delivery"]], "Plain_window"]]
                ]
              ],
              [
                "if", ["OK", "=", "1"],
                [
                  [
                    "if", ["_sor_lrbLeaveOpen", "=", "1"],
                    [
                      ["sor_delivery_state", "=", ""],
                      ["sor_delivery_date", "=", "00.00.0000"],
                      ["sor_waiting_for_delivery", "=", ["sor_ordered_amount", "-", "sor_delivered_before", "-", "sor_delivered_quantity"]]
                    ],
                    "elseif", ["_sor_lrbPartialDelivery", "=", "1"],
                    [
                      [
                        "if", ["_fii_InUse", "=", "false"],
                        [
                          ["_err_MESSAGE", [["_lang_Current", ["Partial_delivery_can_not_be_done_within_row_modification"]], "Current_method_name", "true"]]
                        ],
                        "else",
                        [
                          [
                            "if", ["sor_partial_delivery_number", "=", "0"],
                            [
                              ["sor_partial_delivery_number", "=", "1"]
                            ]
                          ],
                          ["_sor_lPartial_Delivery_Number", "=", ["sor_partial_delivery_number"]],
                          ["sor_delivery_date", "=", ["Current", ["*"]]],
                          ["sor_waiting_for_delivery", "=", ["sor_ordered_amount", "-", "sor_delivered_before", "+", "sor_delivered_quantity"]],
                          ["sor_delivery_state", "=", "OT"],
                          ["sor_L_RIVISUMMAT"],
                          ["_rec_SAVE", ["sor_tbl"]],
                          ["_sor_lRow", "=", ["_fii_SelectedRecordRowGet", ["sor_tbl"]]],
                          [
                            "if", ["_sor_lRow", ">", "0"],
                            [
                              ["_fii_ROW_ADD", ["before", "sor_tbl", "0"]],
                              ["_rec_DUPLICATE", ["sor_tbl"]],
                              ["sor_delivered_quantity", "=", "0"],
                              ["sor_delivered_before", "=", ["sor_ordered_amount", "-", "sor_waiting_for_delivery"]],
                              ["sor_partial_delivery_number", "=", ["_sor_lPartial_Delivery_Number", "+", "1"]],
                              ["sor_delivery_state", "=", ""],
                              ["sor_delivery_date", "=", "00.00.0000"],
                              ["sor_stock_event", "=", ""],
                              ["sor_dispatch_note_id", "=", ""],
                              ["sor_invoice_id", "=", ""],
                              ["sor_pallet_number", "=", ""],
                              ["sor_amount_to_collect", "=", ""],
                              ["sor_collected_amount", "=", ""],
                              ["sor_parcel_code", "=", ""],
                              ["_rec_SAVE", ["sor_tbl"]],
                              ["sor_L_RIVISUMMAT"],
                              ["_rec_SAVE", ["sor_tbl"]],
                              ["_fii_ROW_ADD", ["after", "sor_tbl", ["_sor_lRow", "+", "1"]],
                              ["_fii__ROW_GOTO", ["sor_tbl", "_sor_lRow"]]]
                            ],
                            "else",
                            [
                              ["_err_MESSAGE", [["_lang_Current", ["Record_number_was_not_found"]], "Current_method_name", "true"]]
                            ]
                          ]
                        ]
                      ]
                    ],
                    "else",
                    [
                      ["sor_delivery_date", "=", ["Current_date", ["*"]]],
                      ["sor_waiting_for_delivery", "=", ["sor_ordered_amount", "-", "sor_delivered_before", "-", "sor_delivered_quantity"]],
                      ["sor_delivery_state", "=", "LT"],
                      ["sor_L_RIVISUMMAT"]
                    ]
                  ]
                ],
                "else",
                [
                  ["sor_delivered_quantity", "=", ["sor_ordered_amount", "-", "sor_delivered_before", "-", "sor_waiting_for_delivery"]],
                  [
                    "if", ["_fii_InUse", "=", "true"],
                    [
                      ["_fii_IN_CELL_STAY", ["ture"]]
                    ],
                    "else",
                    [
                      ["GOTO_OBJECT", ["sor_delivered_quantity"]]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ],
      ["_fii_UPDATE_END", ["sor_tbl"]]
    ],
    "sor_scMYYNTIHINTA_": [
      [
        "if", ["g.so_fAleYksHi"],
        [
          [
            "if", ["sor_ordered_amount", "<>", "0"],
            [
              ["sor_price_unit", "=", ["Round", [["sor_sales_price_total", "/", "sor_ordered_amount"], "g.pr_iPyorAHin"]]],
              ["sor_discount_amount", "=", "0"]
            ],
            "else",
            [
              ["sor_price_unit", "=", "0"],
              ["sor_discount_amount", "=", "0"]
            ]
          ],
          ["sor_C_aHINNAT", ["sor_price_unit"]]
        ],
        "else",
        [
          ["sor_discount_amount", "=", ["Round", [["sor_calc_sales_price_total", "-", "sor_sales_price_total"], "2"]]]
        ]
      ],
      [
        "if", ["sor_discount_amount", "=", "0"],
        [
          ["sor_discount_percentage", "=", "0"]
        ],
        "elseif", [["sor_discount_amount", "<>", "0"], "and", ["sor_calc_sales_price_total", "<>", "0"]],
        [
          ["sor_discount_percentage", "=", [["sor_discount_amount", "/", "sor_calc_sales_price_total"], "*", "100"]]
        ],
        "elseif", ["sor_calc_sales_price_total", "=", "0"],
        [
          ["sor_discount_percentage", "=", "0"],
          ["sor_discount_amount", "=", "0"]
        ],
        "else",
        [
          ["xERROR_MESSAGE", ["Tuntematon_CaseOf -kohta", "mrsMYYNTIHINTA_"]]
        ]
      ],
      ["sor_L_RIVISUMMAT"]
    ],
    "sor_scPAK_LKM": [
      ["sor_KPL_MAARA"]
    ],
    "sor_scVARASTOPAIKK": [
      [
        "if", ["sor_parcel_code", "=", ""],
        [
          [
            "if", ["g.mgfOnVarPai"],
            [
              ["pr_SELECT_RECORD", ["sor_product_id"]],
              [
                "if", ["pr_stock_parcel_in_use"],
                [
                  [
                    "if", ["stpa_ChoiceList", ["true", "pr_product_id", "sor_parcel_code"]],
                    [
                      ["sor_parcel_code", "=", ["stpa_parcel_code"]]
                    ]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ],
    "sor_scVAHV_TOI_PV": [
      [
        "if", [["sor_first_conf_delivery_date", ">", "sor_confirmed_delivery_date"], "or", ["sor_first_conf_delivery_date", "=", "00.00.0000"]],
        [
          ["sor_first_conf_delivery_date", "=", ["sor_confirmed_delivery_date"]]
        ]
      ],
      ["sor_L_MUUTTUJAT"]
    ],
    "sor_KPL_MAARA": [
      ["_sel_RELATE_ONE", ["pr_product_id", "sor_product_id"]],
      [
        "if", ["pr_effect_of_fixed_size", "=", "1"],
        [
          [
            "if", ["!aaOptionKey"],
            [
              [
                "if", ["sor_number_of_packets", "=", "0"],
                [
                ]
              ],
              [
                "if", ["sor_packet_length", "=", "0"],
                [
                ],
                "else",
                [
                  ["sor_ordered_amount", "=", ["sor_packet_length", "*", "sor_units_packet", "*", "sor_number_of_packets"]]
                ]
              ]
            ]
          ],
          ["sor_scMAARA_YKS1"]
        ],
        "elseif", ["pr_effect_of_fixed_size", "=", "2"],
        [
          [
            "if", ["!aaOptionKey"],
            [
              [
                "if", ["sor_number_of_packets", "=", "0"],
                [
                ]
              ],
              [
                "if", ["sor_packet_length", "=", "0"],
                [
                  ["sor_rTil_y2", "=", ["sor_units_packet", "*", "sor_number_of_packets"]]
                ],
                "else",
                [
                  ["sor_rTil_y2", "=", ["sor_packet_length", "*", "sor_units_packet", "*", "sor_number_of_packets"]]
                ]
              ]
            ]
          ],
          ["sor_scTIL_Y2"]
        ]
      ]
    ],
    "sor_scTIL_Y2": [
      [
        "if", ["sor_product_id", "<>", ["pr_product_id"]],
        [
          ["RELATE_ONE", ["sor_product_id"]]
        ]
      ],
      [
        "if", [["sor_delivery_state", "=", ""], "and", ["sor_partial_delivery_number", "=", "0"]],
        [
          ["sor_ordered_amount", "=", ["Round", [["sor_rTil_y2", "*", "pr_conversion_multiplier"], "3"]]],
          ["sor_waiting_for_delivery", "=", ["sor_ordered_amount"]],
          ["sor_HAE_RA_TILAVU"],
          ["sor_L_RIVISUMMAT"]
        ],
        "else",
        [
          ["xCRY", ["Osa- ja_loppuntoimituksissa_ei_saa_muuttaa_tilattua_maaraa."]],
          [
            "if", ["pr_conversion_multiplier", "<>", "0"],
            [
              ["sor_rTil_y2", "=", ["sor_ordered_amount", "/", "pr_converison"]]
            ],
            "else",
            [
              ["sor_rTil_y2", "=", "0"]
            ]
          ],
          ["GOTO_OBJECT", ["sor_rTil_y2"]]
        ]
      ],
      ["_err_FIX", ["sor_scTIL_Y2"]],
      ["sor_order_amount_2", "=", ["sor_rTil_y2"]]
    ],
    "sor_scPITUUS": [
      ["sor_KPL_MAARA"]
    ],
    "sor_sc1_VAH_TO_PV": [
      [
        "if", [["sor_first_conf_delivery_date", ">", "sor_confirmed_delivery_date"], "or", ["sor_confirmed_delivery_date", "=", "00.00.0000"]],
        [
          ["sor_confirmed_delivery_date", "=", ["sor_first_conf_delivery_date"]],
          ["sor_scVAHV_TOI_PV"]
        ]
      ],
      ["sor_L_MUUTTUJAT"]
    ],
    "sor_scKPL_X_PAK": [
      ["sor_C_KPL_PAK"],
      ["sor_KPL_MAARA"]
    ],
    "sor_C_KPL_PAK": [
      ["sor_units_packet", "=", ["sor_units_x_packet", "*", "sor_units_y_packet"]]
    ],
    "sor_scKPL_Y_PAK": [
      ["sor_C_KPL_PAK"],
      ["sor_KPL_MAARA"]
    ],
    "sor_scTILAVUUS": [
      ["sor_C_MAARAT", ["sor_volume"]]
    ],
    "sor_scMAARA_YKS2": [
      [
        "if", ["sor_product_id", "<>", ["pr_product_id"]],
        [
          ["_sel_RELATE_ONE", ["pr_product_id", "sor_product_id"]]
        ]
      ],
      [
        "if", [["sor_delivery_state", "=", ""], "and", [["sor_partial_delivery_number", "=", "0"], "or", ["g.sor_lAllowPartialDeliveryChange", "=", "true"]]],
        [
          ["sor_C_MAARAT", ["sor_ordered_amount_2"]],
          ["sor_YKS_MUUTOS"]
        ],
        "else",
        [
          ["xCRY", ["Osa- ja_loppuntoimituksissa_ei_saa_muuttaa_tilattua_maaraa."]]
        ]
      ]
    ],
    "sor_YKS_MUUTOS": [
      [
        "if", ["!aaOptionKey"],
        [
          ["RELATE_ONE", ["sor_product_id"]],
          ["_pr_rMuutKerr", "=", ["pr_conversion_multiplier"]],
          [
            "if", ["_pr_rMuutKerr", "<>", "0"],
            [
              "if", ["pr_effecr_of_amount", "=", "1"],
              [
                ["sor_units_packet", "=", ["Round", [["sor_ordered_amount", "/", "_pr_rMuutKerr"], "5"]]]
              ],
              "elseif", ["pr_effecr_of_amount", "=", "2"],
              [
                ["sor_packet_length", "=", ["Round", [["sor_ordered_amount", "/", "_pr_rMuutKerr"], "5"]]]
              ],
              "elseif", ["pr_effecr_of_amount", "=", "3"],
              [
                [
                  "if", ["sor_packet_length", "<>", "0"],
                  [
                    ["sor_units_packet", "=", ["Round", [["sor_rTil_y2", "/", "sor_packet_length"], "5"]]]
                  ]
                ]
              ],
              "elseif", ["pr_effecr_of_amount", "=", "4"],
              [
                [
                  "if", ["sor_units_packet", "<>", "0"],
                  [
                    ["sor_packet_length", "=", ["Round", [["sor_rTil_y2", "/", "sor_units_packet"], "5"]]]
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ],
    "sor_scAHINTA_YKS2": [
      ["sor_C_aHINNAT", ["sor_price_unit_2"]]
    ],
    "sor_scAHINTA_TILAV": [
      ["sor_C_aHINNAT", ["sor_unit_price_volume"]]
    ],
    "sor_scAHINTA_ALV": [
      ["sor_C_aHINNAT", ["sor_price_with_vat_unit"]]
    ],
    "sor_scPRICE_GROUP": [
      ["sor_PRICE__UNIT_SET", ["sor_price_group"]]
    ],
    "sor_PRICE__UNIT_SET": [
      ["_sor_pChangedFld", "=", "arg1"],
      ["_sel_RELATE_ONE", ["pr_product_id", "sor_product_id"]],
      [
        "if", ["sor_type", "=", "LA"],
        [
          ["sor_L_AHINTA", ["pr_cost_price_unit", "true", "_sor_pChangedFld"]]
        ],
        "else",
        [
          ["sor_L_AHINTA", ["pr_sales_price_unit", "true", "_sor_pChangedFld"]]
        ]
      ]
    ],
    "sor_scPRICING_STATE": [
      [
        "if", ["sor_production_lot", "<>", ""],
        [
          "if", [["_qry_Fld", ["0", "wo_production_lot", "=", "sor_production_lot", "", "false", "true"]], ">", "0"],
          [
            ["_WRITE_STATE", ["wo", "true"]],
            ["_rec_LOCKED_WAIT", ["wo", "true"]],
            [
              "if", ["OK", "=", "1"],
              [
                ["_fld_VALUE_LONG_SET", ["set", "wo_pricing_stet", "sor_pricing_state"]],
                ["_sor_fInPostcalc", "=", "false"],
                [
                  "if", ["sor_pricing_state", "<>", "3"],
                  [
                    ["_sor_rSalesPrice", "=", "0"]
                  ],
                  "else",
                  [
                    ["_sor_rSalesPrice", "=", "_fld_ValueReal", ["sor_price_unit"]],
                    [
                      "if", [["wo__IsOpenState", ["sor_price_unit"]], "=", "false"],
                      ["_sor_fInPostcalc", "=", "true"]
                    ]
                  ]
                ],
                ["_fld_VALUE_REAL_SET", ["set", "wo_sales_price_unit", "sor_price_unit"]],
                ["_fld_VALUE", ["set", "wo_in_report", "_sor_fInPostcalc"]],
                ["_rec_SAVE", ["wo"]],
                ["_rec_UNLOAD", ["wo"]]
              ]
            ],
            ["_WRITE_STATE", ["wo", "previous"]]
          ]
        ]
      ]
    ]
  }
}
