Created
April 18, 2013 04:59
-
-
Save hipsterjazzbo/5410243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Determines the reconciliation status of the packing slip | |
* | |
* @return string $status The status of the packing slip. One of 'reconciled', 'partial', or 'unreconciled' | |
*/ | |
function status() | |
{ | |
// Get just the unreconciled item's first, because if it this is 0 we don't need to reconciled ones | |
$unreconciled_items = Actual_item_model::where(['packing_slip_id' => $this->id, 'merchant_invoice_line_item_id' => 0])->find(); | |
// Start as reconciled, to save a redundant if statement later | |
$status = 'reconciled'; | |
// If there are any unreconciled items, it's not reconciled | |
if (count($unreconciled_items) > 0) | |
{ | |
// Now we need the reconciled ones to test whether it's partial or not | |
$reconciled_items = Actual_item_model::where(['packing_slip_id' => $this->id, 'merchant_invoice_line_item_id >' => 0])->find(); | |
// If there is at least one reconciled item, and we're here, it's partially reconciled | |
if (count($reconciled_items) > 0) | |
{ | |
$status = 'partial'; | |
} | |
// Otherwise it's just unreconciled | |
else | |
{ | |
$status = 'unreconciled'; | |
} | |
} | |
return $status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment