Skip to content

Commit

Permalink
PROD-201: Add account receivable field to company
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Shahrukh committed May 24, 2024
1 parent ae46d46 commit eb01054
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 2 deletions.
23 changes: 22 additions & 1 deletion CRM/Financeextras/DAO/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from io.compuco.financeextras/xml/schema/CRM/Financeextras/Company.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:27d0976e548553b606d9349e2d094e16)
* (GenCodeChecksum:5e72b4031277f9e7ff40a4e1eae5e142)
*/
use CRM_Financeextras_ExtensionUtil as E;

Expand Down Expand Up @@ -95,6 +95,13 @@ class CRM_Financeextras_DAO_Company extends CRM_Core_DAO {
*/
public $next_creditnote_number;

/**
* @var int|string|null
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $receivable_payment_method;

/**
* Class constructor.
*/
Expand Down Expand Up @@ -272,6 +279,20 @@ public static function &fields() {
],
'add' => NULL,
],
'receivable_payment_method' => [
'name' => 'receivable_payment_method',
'type' => CRM_Utils_Type::T_INT,
'title' => E::ts('Accounts Receivable Payment Method'),
'where' => 'financeextras_company.receivable_payment_method',
'table_name' => 'financeextras_company',
'entity' => 'Company',
'bao' => 'CRM_Financeextras_DAO_Company',
'localizable' => 0,
'html' => [
'label' => E::ts("Accounts Receivable Payment Method"),
],
'add' => NULL,
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
Expand Down
15 changes: 15 additions & 0 deletions CRM/Financeextras/Form/Company/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ public function buildQuickForm() {

$this->add('text', 'next_creditnote_number', 'Next Credit Note Number', ['maxlength' => 11], TRUE);

$this->addEntityRef(
'receivable_payment_method',
ts('Accounts Receivable Payment Method'),
[
'entity' => 'option_value',
'api' => ['params' => ['option_group_id' => 'payment_instrument']],
'select' => ['minimumInputLength' => 0],
'placeholder' => ts('Select Payment Method'),
'multiple' => FALSE,
],
TRUE
);

$this->addButtons([
[
'type' => 'submit',
Expand Down Expand Up @@ -97,6 +110,7 @@ public function setDefaultValues() {
$values['creditnote_template_id'] = $company->creditnote_template_id;
$values['creditnote_prefix'] = $company->creditnote_prefix;
$values['next_creditnote_number'] = $company->next_creditnote_number;
$values['receivable_payment_method'] = $company->receivable_payment_method;

return $values;
}
Expand Down Expand Up @@ -144,6 +158,7 @@ public function postProcess() {
$params['creditnote_template_id'] = $submittedValues['creditnote_template_id'];
$params['creditnote_prefix'] = $submittedValues['creditnote_prefix'];
$params['next_creditnote_number'] = $submittedValues['next_creditnote_number'];
$params['receivable_payment_method'] = $submittedValues['receivable_payment_method'];

CRM_Financeextras_BAO_Company::create($params);

Expand Down
5 changes: 4 additions & 1 deletion CRM/Financeextras/Page/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ public function run() {
}

public function browse() {
$getQuery = 'SELECT fc.*, cc.display_name as company_name, mt.msg_title as invoice_template_name, mt2.msg_title as creditnote_template_name FROM financeextras_company fc
$optionGroupId = civicrm_api3('OptionGroup', 'Getvalue', ['name' => 'payment_instrument', 'return' => 'id']);

$getQuery = 'SELECT fc.*, cc.display_name as company_name, mt.msg_title as invoice_template_name, mt2.msg_title as creditnote_template_name, ov.label AS receivable_payment_method FROM financeextras_company fc
LEFT JOIN civicrm_contact cc on cc.id = fc.contact_id
LEFT JOIN civicrm_msg_template mt ON mt.id = fc.invoice_template_id
LEFT JOIN civicrm_msg_template mt2 ON mt2.id = fc.creditnote_template_id
LEFT JOIN civicrm_option_value ov ON ov.value = fc.receivable_payment_method AND ov.option_group_id = ' . $optionGroupId . ' ORDER BY fc.id DESC
';
$company = CRM_Core_DAO::executeQuery($getQuery);
$rows = [];
Expand Down
10 changes: 10 additions & 0 deletions CRM/Financeextras/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,14 @@ public function upgrade_1001() {
return TRUE;
}

/**
* This upgrade updates company table
*/
public function upgrade_1002() {
$this->ctx->log->info('Applying update 1002');
$this->executeSqlFile('sql/upgrade_1002.sql');

return TRUE;
}

}
1 change: 1 addition & 0 deletions sql/auto_install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ CREATE TABLE `financeextras_company` (
`creditnote_template_id` int unsigned COMMENT 'FK to the message template.',
`creditnote_prefix` varchar(11),
`next_creditnote_number` varchar(11),
`receivable_payment_method` int unsigned ,
PRIMARY KEY (`id`),
CONSTRAINT FK_financeextras_company_contact_id FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE CASCADE,
CONSTRAINT FK_financeextras_company_invoice_template_id FOREIGN KEY (`invoice_template_id`) REFERENCES `civicrm_msg_template`(`id`) ON DELETE SET NULL,
Expand Down
8 changes: 8 additions & 0 deletions sql/upgrade_1002.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- /*******************************************************
-- *
-- * financeextras_company
-- *
-- * Add receivable_payment_method column.
-- *
-- *******************************************************/
ALTER TABLE `financeextras_company` ADD COLUMN receivable_payment_method int unsigned;
8 changes: 8 additions & 0 deletions templates/CRM/Financeextras/Form/Company/Add.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
<td class="label">{$form.next_creditnote_number.label}</td>
<td>{$form.next_creditnote_number.html}</td>
</tr>

<tr>
<td class="label">
{$form.receivable_payment_method.label}
{help id="receivable_payment_method" file="CRM/Financeextras/ReceivablePaymentMethod.hlp"}
</td>
<td>{$form.receivable_payment_method.html}</td>
</tr>
</tbody>
</table>
<div class="crm-submit-buttons">
Expand Down
2 changes: 2 additions & 0 deletions templates/CRM/Financeextras/Page/Company.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<th>{ts}Credit Note Template{/ts}</th>
<th>{ts}Credit Note Prefix{/ts}</th>
<th>{ts}Next Credit Note Number{/ts}</th>
<th>{ts}Accounts Receivable Payment Method{/ts}</th>
<th></th>
</tr>
</thead>
Expand All @@ -27,6 +28,7 @@
<td>{$row.creditnote_template_name}</td>
<td>{$row.creditnote_prefix}</td>
<td>{$row.next_creditnote_number}</td>
<td>{$row.receivable_payment_method}</td>
<td>{$row.action|replace:'xx':$row.id}</td>
</tr>
{/foreach}
Expand Down
11 changes: 11 additions & 0 deletions templates/CRM/Financeextras/ReceivablePaymentMethod.hlp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{htxt id="receivable_payment_method"}
<p>
{ts}Each company requires a payment method to be used as the accounts receivable account for unpaid invoices. This is created automatically for the first company. For additional companies please create this before creating the Company by:{/ts}
</p>
<ol style="margin-left: 5px;">
<li>Create a contact for this legal entity / company.</li>
<li>Create an “Asset” financial account where the “owner” is the contact above.</li>
<li>Create a payment method called “Accounts Receivable” with your relevant accounting codes. Set the payment method to be hidden.</li>
<li>Select the payment method in this field.</li>
</ol>
{/htxt}
5 changes: 5 additions & 0 deletions tests/phpunit/CRM/Financeextras/Form/Company/AddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function testRequiredFieldsValidation() {
'creditnote_template_id' => '',
'creditnote_prefix' => '',
'next_creditnote_number' => '',
'receivable_payment_method' => '',
];
$form = $this->submitForm($formValues);
$actualErrors = $form->_errors;
Expand All @@ -24,6 +25,7 @@ public function testRequiredFieldsValidation() {
'next_invoice_number' => 'Next Invoice Number is a required field.',
'creditnote_template_id' => 'Credit Note Template is a required field.',
'next_creditnote_number' => 'Next Credit Note Number is a required field.',
'receivable_payment_method' => 'Accounts Receivable Payment Method is a required field.',
];

$this->assertEquals($expectedErrors, $actualErrors);
Expand All @@ -38,6 +40,7 @@ public function testNumericalFieldsValidation() {
'creditnote_template_id' => 1,
'creditnote_prefix' => 'CN_',
'next_creditnote_number' => 'YAYAYA',
'receivable_payment_method' => 1,
];

$form = $this->submitForm($formValues);
Expand All @@ -60,6 +63,7 @@ public function testAddingNewCompanySuccessfully() {
'creditnote_template_id' => 1,
'creditnote_prefix' => 'CN_',
'next_creditnote_number' => '00002',
'receivable_payment_method' => 1,
];

$this->submitForm($formValues);
Expand All @@ -86,6 +90,7 @@ public function testUpdatingCompanySuccessfully() {
'creditnote_template_id' => 1,
'creditnote_prefix' => 'CN_',
'next_creditnote_number' => '000002',
'receivable_payment_method' => 1,
];
$company = CRM_Financeextras_BAO_Company::create($params);

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/CRM/Financeextras/Page/CompanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function testCompanyRecordsAppearInPage() {
'next_invoice_number' => '000001',
'creditnote_prefix' => 'CN',
'next_creditnote_number' => '000002',
'receivable_payment_method' => 1,
];
CRM_Financeextras_BAO_Company::create($params1);

Expand All @@ -26,6 +27,7 @@ public function testCompanyRecordsAppearInPage() {
'next_invoice_number' => '000005',
'creditnote_prefix' => 'XH',
'next_creditnote_number' => '000006',
'receivable_payment_method' => 2,
];
CRM_Financeextras_BAO_Company::create($params2);

Expand Down
9 changes: 9 additions & 0 deletions xml/schema/CRM/Financeextras/Company.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,13 @@
<type>Text</type>
</html>
</field>

<field>
<name>receivable_payment_method</name>
<title>Accounts Receivable Payment Method</title>
<type>int unsigned</type>
<html>
<label>Accounts Receivable Payment Method</label>
</html>
</field>
</table>

0 comments on commit eb01054

Please sign in to comment.