app/Http/Controllers/AutomationPurchaseRequestMappingController.php
// If warehouse fulfill the quantity of item, mapped to Dispatch Instruction, and return true
If warehouse fulfill the quantity of item, mapped to Dispatch Instruction, and return true
If warehouse fulfill the quantity of item mapped to Dispatch Instruction and return true
public function processWarehouse($branchID, $requestID, $itemID, $quantity) {
		(int)$currentQuantity = $quantity;
		$warehouse = Branch::where("name","Warehouse")->pluck("branchID")[0];
		$branchItem = BranchItem::where("branchID", $warehouse)->where("itemID", $itemID)->first();
		if($branchItem == null) {
			return $currentQuantity;
		}
		if($branchItem->quantity >= $currentQuantity) {
			$currentQuantity = $branchItem->quantity - $currentQuantity;
			BranchItem::where("branchID", $warehouse)->where("itemID", $itemID)->update(["quantity"=>$currentQuantity]);
			$this->updateDispatchInstruction($requestID, $itemID, $quantity, 0);
			$this->updatePurchaseRequest($requestID);
			$this->updatePurchaseRequestItem($requestID, $itemID, 0);
			return 0;
		}
		$currentQuantity = $currentQuantity - $branchItem->quantity;
		BranchItem::where("branchID", $warehouse)->where("itemID", $itemID)->update(["quantity"=>0]);
		$this->updateDispatchInstruction($requestID, $itemID, $branchItem->quantity , 0);
		return $currentQuantity; 
	}
public function processWarehouse ( $ branchID , $ requestID , $ itemID , $ quantity ) { ( int ) $ currentQuantity = $ quantity ; $ warehouse = Branch :: where ( " name " , " Warehouse " ) -> pluck ( " branchID " ) [ 0 ] ; $ branchItem = BranchItem :: where ( " branchID " , $ warehouse ) -> where ( " itemID " , $ itemID ) -> first ( ) ; if ( $ branchItem == null ) { return $ currentQuantity ; } if ( $ branchItem -> quantity >= $ currentQuantity ) { $ currentQuantity = $ branchItem -> quantity - $ currentQuantity ; BranchItem :: where ( " branchID " , $ warehouse ) -> where ( " itemID " , $ itemID ) -> update ( [ " quantity " => $ currentQuantity ] ) ; $ this -> updateDispatchInstruction ( $ requestID , $ itemID , $ quantity , 0 ) ; $ this -> updatePurchaseRequest ( $ requestID ) ; $ this -> updatePurchaseRequestItem ( $ requestID , $ itemID , 0 ) ; return 0 ; } $ currentQuantity = $ currentQuantity - $ branchItem -> quantity ; BranchItem :: where ( " branchID " , $ warehouse ) -> where ( " itemID " , $ itemID ) -> update ( [ " quantity " => 0 ] ) ; $ this -> updateDispatchInstruction ( $ requestID , $ itemID , $ branchItem -> quantity , 0 ) ; return $ currentQuantity ; }
If warehouse fulfill the quantity of item, mapped to Dispatch Instruction, and return true
If warehouse fulfill the quantity of item mapped to Dispatch Instruction and return true
//echo "Called Warehouse"; //Branch Storage can handle the quantity of order. //Branch Storage cannot handle the quantity of order.