Skip to content

Instantly share code, notes, and snippets.

@hipsterjazzbo
Created April 18, 2013 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hipsterjazzbo/5410243 to your computer and use it in GitHub Desktop.
Save hipsterjazzbo/5410243 to your computer and use it in GitHub Desktop.
/**
* 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