{
	"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",
				[
					"wpa/update_finished_work_phase_machine_time",
					{
						"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",
						[
							"wpa_record_id",
							"wpa_change_id",
							"wpa_machine_hours",
							"wpa_setup_time__amount"
						]
					]
				]
			],
			[
				"errWpa",
				"=",
				[
					"saveToDatabaseNotUpdated",
					[
						"4d",
						"wpaSaveArr"
					]
				]
			],
			[
				"if",
				[
					"errWpa",
					"is empty"
				],
				[
					[
						"save_to_result_cache"
					]
				]
			]
		],
		"previous_change_id_exist": [
			[
				"previousChangeId",
				"=",
				"prevSavedChangeId"
			]
		],
		"previous_change_id_not_exist": [
			[
				"previousChangeId",
				"=",
				""
			]
		],
		"save_to_result_cache":[
			[
				"recordIdArray","=",["fieldValueToArray",["wpaTbl","wpa_record_id"]]
			],
			[
				"changeIdTbl","=",["query",["wpa/selection_with_record_id_array",{"record_id_array":"recordIdArray", "field": ["wpa_change_id"]}]]
			],
			[
				"lastChangeId","=",["fieldMaxValue",["changeIdTbl","wpa_change_id"]]
			],
			[
				"newSavedChangeId","=",["saveResultCache",["update_finished_work_phase_machine_time",{"previous_check":"lastChangeId"}]]
			]
		]
	},
	"name": "update_finished_work_phase_machine_time"
}
