{
	"run": [
		[
			"prevSavedChangeId",
			"=",
			[
				"loadResultCache",
				["update_finished_work_phase_machine_time", "previous_check"]
			]
		],
		[
			"if",
			["prevSavedChangeId", "is empty"],
			[["previous_change_id_not_exist"]],
			"else",
			[["previous_change_id_exist"]]
		],
		["endDate", "=", ["currentDateString"]],
		["startDate", "=", ["daysAdd", ["endDate", "days_before"]]],
		[
			"wpaTbl",
			"=",
			[
				"query",
				[
					"query/manager/product/product_work/actual/update_finished_work_phase_machine_time.json",
					{
						"start_date": "startDate",
						"previous_change_id": "previousChangeId"
					}
				]
			]
		],
		["if", ["wpaTbl", "is empty"], [[""]], "else", [["update_and_save"]]]
	],
	"database": "4d",
	"info": "update_finished_work_phase_machine_time... ",
	"days_before": -100,
	"function": {
		"update_and_save": [
			[
				"wpaTbl",
				"=",
				["updateWorkTime", ["wpaTbl", " machine_time setup_time "]]
			],
			[
				"wpaTblOverlapCleared",
				"=",
				["clearOverlappedMachineTime", ["wpaTbl", " setup_time "]]
			],
			[
				"wpaSaveArr",
				"=",
				[
					"selectFieldsFromArray",
					[
						"wpaTblOverlapCleared",
						[
							"prwo.record_id",
							"prwo.modify_id",
							"prwo.machine_hours",
							"prwo.setup_hours"
						]
					]
				]
			],
			["errWpa", "=", ["saveToDatabaseNotUpdated", ["4d", "wpaSaveArr"]]],
			["if", ["errWpa", "is empty"], [["save_to_result_cache"]]]
		],
		"previous_change_id_exist": [
			["previousChangeId", "=", "prevSavedChangeId"]
		],
		"save_to_result_cache": [
			[
				"recordIdArray",
				"=",
				["fieldValueToArray", ["wpaTbl", "prwo.record_id"]]
			],
			[
				"changeIdTbl",
				"=",
				[
					"query",
					[
						"query/manager/product/product_work/actual/selection_with_record_id_array.json",
						{
							"record_id_array": "recordIdArray",
							"field": ["prwo.modify_id"]
						}
					]
				]
			],
			[
				"lastChangeId",
				"=",
				["fieldMaxValue", ["changeIdTbl", "prwo.modify_id"]]
			],
			[
				"newSavedChangeId",
				"=",
				[
					"saveResultCache",
					[
						"update_finished_work_phase_machine_time",
						{
							"previous_check": "lastChangeId"
						}
					]
				]
			]
		],
		"previous_change_id_not_exist": [["previousChangeId", "=", ""]]
	},
	"name": "run_code/update_finished_work_phase_machine_time.json"
}
