app/Http/Controllers/MapPurchaseRequestController.php
//set all value when submit lists and values
set all value when submit lists and values
set all value when submit lists and values
public function submitAgreementAndInventory(Request $request) {
        $agreementList = [];
        $branchList= [];
        $requestID = $request->requestID;
        $agreementQuantity = $request->agreementQuantity;
        $agreementID = $request->agreementID;
        $agreementRevision = $request->agreementRevision;
        $agreementItemID = $request->agreementItemID;
        $branchQuantity = $request->branchQuantity;
        $branchID = $request->branchID;
        $branchItemID = $request->branchItemID;
        if($agreementQuantity != null) {
            for($item = 0; $item < count($agreementQuantity); $item++) {
                if($agreementQuantity[$item] != null) {
                    if($this->agreementValidation($agreementID[$item], $agreementRevision[$item],  $agreementItemID[$item], $agreementQuantity[$item]) == false) {
                         return back()->withErrors('Your purchase quantity is larger than agreement quantity');
                    }
                    array_push($agreementList, ["agreementID" => $agreementID[$item], "revision" => $agreementRevision[$item], "itemID" => $agreementItemID[$item], "quantity" => $agreementQuantity[$item]]);
                }
            }
        }
        if($branchQuantity != null) {
            for($item = 0; $item < count($branchQuantity); $item++) {
                if($branchQuantity[$item] != null) {
                    if($this->inventoryValidation($branchID, $branchItemID[$item], $branchQuantity[$item]) == false) {
                        return back()->withErrors("Your purchase quantity is larager than inventory quantity");
                    }
                    array_push($branchList, ["branchID" => $branchID, "itemID" => $branchItemID[$item], "quantity" => $branchQuantity[$item]]);
                }
            }
        }
        foreach(PurchaseRequestItem::where("requestID", $requestID)->get() as $key) {
            $id = $key->itemID;
            $totalQuantity = 0;
            foreach($agreementList as $value) {
                if($value['itemID'] == $id) {
                    $totalQuantity = $totalQuantity + $value['quantity'];
                }
            }
            foreach($branchList as $value) {
                if($value['itemID'] == $id) {
                    $totalQuantity = $totalQuantity + $value['quantity'];
                }
            }
            if(PurchaseRequestItem::where("requestID", $requestID)->where("itemID", $id)->first()->balance < $totalQuantity) {
                return back()->withErrors('Your purchase total quantity is larger than [ inventory quantity, agreement quantity ].');
            }
        }
        foreach($agreementList as $value) {
            $this->processPurchaseOrder($value['agreementID'], $requestID, $value['revision'], $value['itemID'], $branchID, (int)$value['quantity']);
        }
        foreach($branchList as $value) {
            $this->processInventory($requestID, $value["branchID"], $value["itemID"], $value["quantity"]);
        }
        return back()->with('success',"Successfully Mapped ");
    }
public function submitAgreementAndInventory ( Request $ request ) { $ agreementList = [ ] ; $ branchList = [ ] ; $ requestID = $ request -> requestID ; $ agreementQuantity = $ request -> agreementQuantity ; $ agreementID = $ request -> agreementID ; $ agreementRevision = $ request -> agreementRevision ; $ agreementItemID = $ request -> agreementItemID ; $ branchQuantity = $ request -> branchQuantity ; $ branchID = $ request -> branchID ; $ branchItemID = $ request -> branchItemID ; if ( $ agreementQuantity != null ) { for ( $ item = 0 ; $ item < count ( $ agreementQuantity ) ; $ item ++ ) { if ( $ agreementQuantity [ $ item ] != null ) { if ( $ this -> agreementValidation ( $ agreementID [ $ item ] , $ agreementRevision [ $ item ] , $ agreementItemID [ $ item ] , $ agreementQuantity [ $ item ] ) == false ) { return back ( ) -> withErrors ( 'Your purchase quantity is larger than agreement quantity' ) ; } array_push ( $ agreementList , [ " agreementID " => $ agreementID [ $ item ] , " revision " => $ agreementRevision [ $ item ] , " itemID " => $ agreementItemID [ $ item ] , " quantity " => $ agreementQuantity [ $ item ] ] ) ; } } } if ( $ branchQuantity != null ) { for ( $ item = 0 ; $ item < count ( $ branchQuantity ) ; $ item ++ ) { if ( $ branchQuantity [ $ item ] != null ) { if ( $ this -> inventoryValidation ( $ branchID , $ branchItemID [ $ item ] , $ branchQuantity [ $ item ] ) == false ) { return back ( ) -> withErrors ( " Your purchase quantity is larager than inventory quantity " ) ; } array_push ( $ branchList , [ " branchID " => $ branchID , " itemID " => $ branchItemID [ $ item ] , " quantity " => $ branchQuantity [ $ item ] ] ) ; } } } foreach ( PurchaseRequestItem :: where ( " requestID " , $ requestID ) -> get ( ) as $ key ) { $ id = $ key -> itemID ; $ totalQuantity = 0 ; foreach ( $ agreementList as $ value ) { if ( $ value [ 'itemID' ] == $ id ) { $ totalQuantity = $ totalQuantity + $ value [ 'quantity' ] ; } } foreach ( $ branchList as $ value ) { if ( $ value [ 'itemID' ] == $ id ) { $ totalQuantity = $ totalQuantity + $ value [ 'quantity' ] ; } } if ( PurchaseRequestItem :: where ( " requestID " , $ requestID ) -> where ( " itemID " , $ id ) -> first ( ) -> balance < $ totalQuantity ) { return back ( ) -> withErrors ( 'Your purchase total quantity is larger than [ inventory quantity, agreement quantity ].' ) ; } } foreach ( $ agreementList as $ value ) { $ this -> processPurchaseOrder ( $ value [ 'agreementID' ] , $ requestID , $ value [ 'revision' ] , $ value [ 'itemID' ] , $ branchID , ( int ) $ value [ 'quantity' ] ) ; } foreach ( $ branchList as $ value ) { $ this -> processInventory ( $ requestID , $ value [ " branchID " ] , $ value [ " itemID " ] , $ value [ " quantity " ] ) ; } return back ( ) -> with ( 'success' , " Successfully Mapped  " ) ; }
set all value when submit lists and values
set all value when submit lists and values
// get BranchList / AgreementList and process the list quantity by itemID // After, update agreementList and BranchList