Fundamental Theorem of $P$-Partitions