$error = true;
             }
         }
     } catch (fExpectedException $e) {
         echo $e->printMessage();
         $error = true;
     }
 } else {
     if ($_POST['type'] == "removeStock") {
         $records = Inv_stock::gotoStock($_POST['itemCode'], $_POST['branch']);
         if ($records->count()) {
             foreach ($records as $record) {
                 if ($record->getQuantity() < $_POST['itemQuan']) {
                     echo "Item not enough quantity";
                 } else {
                     Inv_stock::removeStock($_POST['itemCode'], $_POST['branch'], $_POST['itemQuan']);
                     $stock = new Production_issue_detail($_POST['detailId']);
                     $stock->setStatus('completed');
                     $stock->store();
                 }
             }
         } else {
             echo "Item not enough quantity.";
         }
     } else {
         if ($_POST['type'] == "save") {
             try {
                 $production = new Production_issue($_POST['key']);
                 //$production->populate();
                 if ($_POST['issuer'] != "") {
                     $production->setIssuer($_POST['issuer']);
<?php

include '../resources/init.php';
if (isset($_POST['type'])) {
    if ($_POST['type'] == "transfer") {
        $json_form = fRequest::get('jsonForm');
        $jsonForm = fJSON::decode($json_form);
        foreach ($jsonForm as $row) {
            try {
                Inv_stock::removeStock($row->{'itemCode'}, $row->{'branch'}, $row->{'quantity'});
                $mattrans = new Material_transfer($_POST['doc_num']);
                $mattrans->setStatus("completed");
                $mattrans->store();
                $mattrans_detail = new Material_transfer_detail($row->{'id'});
                $mattrans_detail->setFromBranch($row->{'branch'});
                $mattrans_detail->store();
            } catch (fExpectedException $e) {
                echo $e->printMessage();
            }
            Inv_stock::addStock($row->{'itemCode'}, $_POST['branch'], $row->{'quantity'});
        }
    } else {
        if ($_POST['type'] == "ACcount") {
            try {
                $branch = fRequest::get('branch');
                $itemcode = fRequest::get('item');
                $stocks = Inv_stock::findStockByBranch($itemcode, $branch);
                $stock = $stocks[0];
                echo $stock->prepareQuantity();
            } catch (fExpectedException $e) {
                echo $e->printMessage();