forked from civicrm/org.civicrm.civicase
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1005 from compucorp/BTHAB-3-workstream
BTHAB-3: Merging workstream branch to master
- Loading branch information
Showing
142 changed files
with
11,050 additions
and
842 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* CaseCategoryFeatures BAO. | ||
*/ | ||
class CRM_Civicase_BAO_CaseCategoryFeatures extends CRM_Civicase_DAO_CaseCategoryFeatures { | ||
|
||
/** | ||
* Create a new CaseCategoryFeatures based on array-data. | ||
* | ||
* @param array $params | ||
* Key-value pairs. | ||
* | ||
* @return CRM_Civicase_DAO_CaseCategoryFeatures|null | ||
* Case category feature. | ||
*/ | ||
public static function create(array $params) { | ||
$className = 'CRM_Civicase_DAO_CaseCategoryFeatures'; | ||
$entityName = 'CaseCategoryFeatures'; | ||
$hook = empty($params['id']) ? 'create' : 'edit'; | ||
|
||
CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); | ||
$instance = new $className(); | ||
$instance->copyValues($params); | ||
$instance->save(); | ||
CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); | ||
|
||
return $instance; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
/** | ||
* CaseSalesOrder BAO. | ||
*/ | ||
class CRM_Civicase_BAO_CaseSalesOrder extends CRM_Civicase_DAO_CaseSalesOrder { | ||
|
||
/** | ||
* Create a new CaseSalesOrder based on array-data. | ||
* | ||
* @param array $params | ||
* Key-value pairs. | ||
* | ||
* @return CRM_Civicase_DAO_CaseSalesOrder|null | ||
* Case sales order instance. | ||
*/ | ||
public static function create(array $params) { | ||
$className = 'CRM_Civicase_DAO_CaseSalesOrder'; | ||
$entityName = 'CaseSalesOrder'; | ||
$hook = empty($params['id']) ? 'create' : 'edit'; | ||
|
||
CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); | ||
$instance = new $className(); | ||
$instance->copyValues($params); | ||
$instance->save(); | ||
CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); | ||
|
||
return $instance; | ||
} | ||
|
||
/** | ||
* Computes the sales order line item total. | ||
* | ||
* @param array $items | ||
* Array of sales order line items. | ||
* | ||
* @return array | ||
* ['totalAfterTax' => <value>, 'totalBeforeTax' => <value>] | ||
*/ | ||
public static function computeTotal(array $items) { | ||
$totalBeforeTax = round(array_reduce($items, fn ($a, $b) => $a + self::getSubTotal($b), 0), 2); | ||
$totalAfterTax = round(array_reduce($items, | ||
fn ($a, $b) => $a + (($b['tax_rate'] * self::getSubTotal($b)) / 100), | ||
0 | ||
) + $totalBeforeTax, 2); | ||
|
||
return [ | ||
'taxRates' => self::computeTaxRates($items), | ||
'totalAfterTax' => $totalAfterTax, | ||
'totalBeforeTax' => $totalBeforeTax, | ||
]; | ||
} | ||
|
||
/** | ||
* Computes the sub total of a single line item. | ||
* | ||
* @param array $item | ||
* Single sales order line item. | ||
* | ||
* @return int | ||
* The line item subtotal. | ||
*/ | ||
public static function getSubTotal(array $item) { | ||
return $item['unit_price'] * $item['quantity'] * ((100 - ($item['discounted_percentage'] ?? 0)) / 100) ?? 0; | ||
} | ||
|
||
/** | ||
* Computes the tax rates of each line item. | ||
* | ||
* @param array $items | ||
* Single sales order line item. | ||
* | ||
* @return array | ||
* Returned sorted array of line items tax rates. | ||
*/ | ||
public static function computeTaxRates(array $items) { | ||
$items = array_filter($items, fn ($a) => $a['tax_rate'] > 0); | ||
usort($items, fn ($a, $b) => $a['tax_rate'] <=> $b['tax_rate']); | ||
|
||
return array_map( | ||
fn ($a) => | ||
[ | ||
'rate' => round($a['tax_rate'], 2), | ||
'value' => round(($a['tax_rate'] * self::getSubTotal($a)) / 100, 2), | ||
], | ||
$items | ||
); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* CaseSalesOrderLine BAO. | ||
*/ | ||
class CRM_Civicase_BAO_CaseSalesOrderLine extends CRM_Civicase_DAO_CaseSalesOrderLine { | ||
|
||
/** | ||
* Create a new CaseSalesOrderLine based on array-data. | ||
* | ||
* @param array $params | ||
* Key-value pairs. | ||
* | ||
* @return CRM_Civicase_DAO_CaseSalesOrderLine|null | ||
* CRM_Civicase_DAO_CaseSalesOrderLine | ||
*/ | ||
public static function create(array $params) { | ||
$className = 'CRM_Civicase_DAO_CaseSalesOrderLine'; | ||
$entityName = 'CaseSalesOrderLine'; | ||
$hook = empty($params['id']) ? 'create' : 'edit'; | ||
|
||
CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params); | ||
$instance = new $className(); | ||
$instance->copyValues($params); | ||
$instance->save(); | ||
CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance); | ||
|
||
return $instance; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
<?php | ||
|
||
/** | ||
* @package CRM | ||
* @copyright CiviCRM LLC https://civicrm.org/licensing | ||
* | ||
* Generated from uk.co.compucorp.civicase/xml/schema/CRM/Civicase/CaseCategoryFeatures.xml | ||
* DO NOT EDIT. Generated by CRM_Core_CodeGen | ||
* (GenCodeChecksum:480eebcac1f7ce6976ee6dd5a87112e8) | ||
*/ | ||
use CRM_Civicase_ExtensionUtil as E; | ||
|
||
/** | ||
* Database access object for the CaseCategoryFeatures entity. | ||
*/ | ||
class CRM_Civicase_DAO_CaseCategoryFeatures extends CRM_Core_DAO { | ||
const EXT = E::LONG_NAME; | ||
const TABLE_ADDED = ''; | ||
|
||
/** | ||
* Static instance to hold the table name. | ||
* | ||
* @var string | ||
*/ | ||
public static $_tableName = 'civicrm_case_category_features'; | ||
|
||
/** | ||
* Should CiviCRM log any modifications to this table in the civicrm_log table. | ||
* | ||
* @var bool | ||
*/ | ||
public static $_log = TRUE; | ||
|
||
/** | ||
* Unique CaseCategoryFeatures ID | ||
* | ||
* @var int|string|null | ||
* (SQL type: int unsigned) | ||
* Note that values will be retrieved from the database as a string. | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* One of the values of the case_type_categories option group | ||
* | ||
* @var int|string | ||
* (SQL type: int unsigned) | ||
* Note that values will be retrieved from the database as a string. | ||
*/ | ||
public $category_id; | ||
|
||
/** | ||
* One of the values of the case_type_category_features option group | ||
* | ||
* @var int|string | ||
* (SQL type: int unsigned) | ||
* Note that values will be retrieved from the database as a string. | ||
*/ | ||
public $feature_id; | ||
|
||
/** | ||
* Class constructor. | ||
*/ | ||
public function __construct() { | ||
$this->__table = 'civicrm_case_category_features'; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Returns localized title of this entity. | ||
* | ||
* @param bool $plural | ||
* Whether to return the plural version of the title. | ||
*/ | ||
public static function getEntityTitle($plural = FALSE) { | ||
return $plural ? E::ts('Case Category Featureses') : E::ts('Case Category Features'); | ||
} | ||
|
||
/** | ||
* Returns all the column names of this table | ||
* | ||
* @return array | ||
*/ | ||
public static function &fields() { | ||
if (!isset(Civi::$statics[__CLASS__]['fields'])) { | ||
Civi::$statics[__CLASS__]['fields'] = [ | ||
'id' => [ | ||
'name' => 'id', | ||
'type' => CRM_Utils_Type::T_INT, | ||
'description' => E::ts('Unique CaseCategoryFeatures ID'), | ||
'required' => TRUE, | ||
'where' => 'civicrm_case_category_features.id', | ||
'table_name' => 'civicrm_case_category_features', | ||
'entity' => 'CaseCategoryFeatures', | ||
'bao' => 'CRM_Civicase_DAO_CaseCategoryFeatures', | ||
'localizable' => 0, | ||
'html' => [ | ||
'type' => 'Number', | ||
], | ||
'readonly' => TRUE, | ||
'add' => NULL, | ||
], | ||
'category_id' => [ | ||
'name' => 'category_id', | ||
'type' => CRM_Utils_Type::T_INT, | ||
'description' => E::ts('One of the values of the case_type_categories option group'), | ||
'required' => TRUE, | ||
'where' => 'civicrm_case_category_features.category_id', | ||
'table_name' => 'civicrm_case_category_features', | ||
'entity' => 'CaseCategoryFeatures', | ||
'bao' => 'CRM_Civicase_DAO_CaseCategoryFeatures', | ||
'localizable' => 0, | ||
'pseudoconstant' => [ | ||
'optionGroupName' => 'case_type_categories', | ||
'optionEditPath' => 'civicrm/admin/options/case_type_categories', | ||
], | ||
'add' => NULL, | ||
], | ||
'feature_id' => [ | ||
'name' => 'feature_id', | ||
'type' => CRM_Utils_Type::T_INT, | ||
'description' => E::ts('One of the values of the case_type_category_features option group'), | ||
'required' => TRUE, | ||
'where' => 'civicrm_case_category_features.feature_id', | ||
'table_name' => 'civicrm_case_category_features', | ||
'entity' => 'CaseCategoryFeatures', | ||
'bao' => 'CRM_Civicase_DAO_CaseCategoryFeatures', | ||
'localizable' => 0, | ||
'pseudoconstant' => [ | ||
'optionGroupName' => 'case_type_category_features', | ||
'optionEditPath' => 'civicrm/admin/options/case_type_category_features', | ||
], | ||
'add' => NULL, | ||
], | ||
]; | ||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); | ||
} | ||
return Civi::$statics[__CLASS__]['fields']; | ||
} | ||
|
||
/** | ||
* Return a mapping from field-name to the corresponding key (as used in fields()). | ||
* | ||
* @return array | ||
* Array(string $name => string $uniqueName). | ||
*/ | ||
public static function &fieldKeys() { | ||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) { | ||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); | ||
} | ||
return Civi::$statics[__CLASS__]['fieldKeys']; | ||
} | ||
|
||
/** | ||
* Returns the names of this table | ||
* | ||
* @return string | ||
*/ | ||
public static function getTableName() { | ||
return self::$_tableName; | ||
} | ||
|
||
/** | ||
* Returns if this table needs to be logged | ||
* | ||
* @return bool | ||
*/ | ||
public function getLog() { | ||
return self::$_log; | ||
} | ||
|
||
/** | ||
* Returns the list of fields that can be imported | ||
* | ||
* @param bool $prefix | ||
* | ||
* @return array | ||
*/ | ||
public static function &import($prefix = FALSE) { | ||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'case_category_features', $prefix, []); | ||
return $r; | ||
} | ||
|
||
/** | ||
* Returns the list of fields that can be exported | ||
* | ||
* @param bool $prefix | ||
* | ||
* @return array | ||
*/ | ||
public static function &export($prefix = FALSE) { | ||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'case_category_features', $prefix, []); | ||
return $r; | ||
} | ||
|
||
/** | ||
* Returns the list of indices | ||
* | ||
* @param bool $localize | ||
* | ||
* @return array | ||
*/ | ||
public static function indices($localize = TRUE) { | ||
$indices = []; | ||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; | ||
} | ||
|
||
} |
Oops, something went wrong.