$mattrans = new Material_transfer($mattrans_detail->getDocNumber());
                                if ($mattrans_detail->getStatus() != "transit") {
                                    throw new fProgrammerException('Status Overidden: ' . $mattrans_detail->getStatus());
                                }
                                Inv_stock::moveTransit($mattrans_detail->getItemId(), $mattrans->getBranchFrom(), $mattrans->getBranchTo(), $mattrans_detail->getQuantity());
                                $mattrans_detail->setStatus("completed");
                                $mattrans_detail->setReceiver($_POST['user']);
                                $mattrans_detail->store();
                                $mat_details = Material_transfer_detail::findDetail($mattrans->getDocNumber());
                                foreach ($mat_details as $mat_detail) {
                                    if ($mat_detail->getStatus() == "completed") {
                                        $mattrans->setStatus("completed");
                                    } else {
                                        $mattrans->setStatus("pending");
                                    }
                                }
                                $mattrans->store();
                            } catch (fExpectedException $e) {
                                echo $e->printMessage();
                            }
                        } else {
                            if ($_POST['type'] == "deleteDetail") {
                                Material_transfer_detail::deleteDetail($_POST['key']);
                            }
                        }
                    }
                }
            }
        }
    }
}