farmOS/modules/farm/farm_ledger/farm_ledger.module

114 lines
2.9 KiB
Plaintext

<?php
/**
* @file
* Code for the Farm Ledger feature.
*/
include_once 'farm_ledger.features.inc';
/**
* Implements hook_farm_ui_entities().
*/
function farm_ledger_farm_ui_entities() {
return array(
'log' => array(
'farm_purchase' => array(
'label' => t('Purchase'),
'label_plural' => t('Purchases'),
'view' => 'farm_log_purchase',
'areas' => TRUE,
'weight' => 90,
),
'farm_sale' => array(
'label' => t('Sale'),
'label_plural' => t('Sales'),
'view' => 'farm_log_sale',
'areas' => TRUE,
'weight' => 90,
),
),
);
}
/**
* Implements hook_feeds_importer_default_alter().
*/
function farm_ledger_feeds_importer_default_alter(&$importers) {
// Add extra field mappings to sale and purchase log importers.
$names = array(
'log_farm_sale',
'log_farm_purchase',
);
foreach ($names as $name) {
if (!empty($importers[$name])) {
// Build an array of common mappings shared by both sales and purchases.
$mappings = array(
array(
'source' => 'Invoice number',
'target' => 'field_farm_invoice_number',
'unique' => FALSE,
'language' => 'und',
),
array(
'source' => 'Lot number',
'target' => 'field_farm_lot_number',
'unique' => FALSE,
'language' => 'und',
),
array(
'source' => 'Quantity',
'target' => 'field_farm_quantity_value',
'unique' => FALSE,
'language' => 'und',
),
array(
'source' => 'Units',
'target' => 'field_farm_quantity_units',
'term_search' => '0',
'autocreate' => 1,
'unique' => FALSE,
'language' => 'und',
),
array(
'source' => 'Unit price',
'target' => 'field_farm_unit_price',
'unique' => FALSE,
'language' => 'und',
),
array(
'source' => 'Total price',
'target' => 'field_farm_total_price',
'unique' => FALSE,
'language' => 'und',
),
);
// Sale logs also have a customer field.
if ($name == 'log_farm_sale') {
$mappings[] = array(
'source' => 'Customer',
'target' => 'field_farm_customer',
'unique' => FALSE,
'language' => 'und',
);
}
// Purchase logs also have a seller field.
elseif ($name == 'log_farm_purchase') {
$mappings[] = array(
'source' => 'Seller',
'target' => 'field_farm_seller',
'unique' => FALSE,
'language' => 'und',
);
}
// Merge the extra mappings into the importer.
$importer_mappings =& $importers[$name]->config['processor']['config']['mappings'];
$importer_mappings = array_merge($importer_mappings, $mappings);
}
}
}