public function InvoiceRestModel::mapFromNode in Invoice 7
Maps the model from the specified node
Parameters
object $node:
File
- ./
invoice_classes.inc, line 130
Class
- InvoiceRestModel
- REST invoice model that is used for binding request data and returning the entity result
Code
public function mapFromNode($node) {
// Set node ID
$this->nid = (int) $node->nid;
// Set invoice properties
$this->id = (int) $node->invoice['invoice_number'];
$this->number = _invoice_get_formatted_invoice_number($node->invoice['formatted_invoice_number'], NULL, $node->created);
$this->leading_zeros = (int) $node->invoice['invoice_number_zerofill'];
$this->prefix = $node->invoice['invoice_number_prefix'];
$this->description = $node->invoice['description'];
$this->template = $node->invoice['template'];
$this->pay_limit = (int) $node->invoice['pay_limit'];
$this->pay_status = $node->invoice['pay_status'];
$vatData = $node->invoice['vat'];
$vatTotals = array();
foreach ($vatData as $vat => $fields) {
$vatTotals[] = array_merge(array(
'vat' => (double) $vat,
), $fields);
}
$this->vat_totals = $vatTotals;
$this->vattotal = (double) $node->invoice['vattotal'];
$this->extotal = (double) $node->invoice['extotal'];
$this->inctotal = (double) $node->invoice['inctotal'];
$this->formatted_vattotal = $node->invoice['formatted_vattotal'];
$this->formatted_extotal = $node->invoice['formatted_extotal'];
$this->formatted_inctotal = $node->invoice['formatted_inctotal'];
$this->formatted_created = $node->invoice['formatted_created'];
$this->created = date('Y-m-d H:i:s', $node->created);
$this->changed = date('Y-m-d H:i:s', $node->changed);
// Set customer
$this->customer['id'] = (int) $node->customer['cid'];
$this->customer['customer_number'] = (int) $node->customer['customer_number'];
$this->customer['company_name'] = $node->customer['company_name'];
$this->customer['firstname'] = $node->customer['firstname'];
$this->customer['lastname'] = $node->customer['lastname'];
$this->customer['street'] = $node->customer['street'];
$this->customer['building_number'] = $node->customer['building_number'];
$this->customer['zipcode'] = $node->customer['zipcode'];
$this->customer['city'] = $node->customer['city'];
$this->customer['state'] = $node->customer['state'];
$this->customer['country'] = $node->customer['country'];
$this->customer['coc_number'] = $node->customer['coc_number'];
$this->customer['vat_number'] = $node->customer['vat_number'];
$this->customer['description'] = $node->customer['description'];
// Set items
$this->items = array();
foreach ($node->invoice_items as $item) {
$item = array_merge(array(
'id' => $item['iid'],
), $item);
unset($item['iid']);
$item['id'] = (int) $item['id'];
$item['quantity'] = (double) $item['quantity'];
$item['unitcost'] = (double) $item['unitcost'];
$item['vat'] = (double) $item['vat'];
$item['weight'] = (int) $item['weight'];
$this->items[] = $item;
}
}