Commit 1f4facc2 authored by Monish Deb's avatar Monish Deb

fix account batch transactions form and use library to translate number into words

parent 5998bdb4
*~
*.bak
grantprograms_data_define.php
\ No newline at end of file
grantprograms_data_define.php
vendor
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2011 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2011
* $Id$
*
*/
require_once __DIR__ . '/../../../vendor/autoload.php';
/**
* This class contains grant program related functions.
......@@ -458,112 +426,8 @@ WHERE civicrm_contact.id = $id ";
);
}
public static function convertNumberToWords($number) {
$hyphen = '-';
$conjunction = ' and ';
$separator = ', ';
$negative = 'negative ';
$decimal = ' and ';
$dictionary = array(
0 => 'zero',
1 => 'one',
2 => 'two',
3 => 'three',
4 => 'four',
5 => 'five',
6 => 'six',
7 => 'seven',
8 => 'eight',
9 => 'nine',
10 => 'ten',
11 => 'eleven',
12 => 'twelve',
13 => 'thirteen',
14 => 'fourteen',
15 => 'fifteen',
16 => 'sixteen',
17 => 'seventeen',
18 => 'eighteen',
19 => 'nineteen',
20 => 'twenty',
30 => 'thirty',
40 => 'fourty',
50 => 'fifty',
60 => 'sixty',
70 => 'seventy',
80 => 'eighty',
90 => 'ninety',
100 => 'hundred',
1000 => 'thousand',
1000000 => 'million',
1000000000 => 'billion',
1000000000000 => 'trillion',
1000000000000000 => 'quadrillion',
1000000000000000000 => 'quintillion'
);
if (!is_numeric($number)) {
return FALSE;
}
if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
// overflow
trigger_error(
'convertNumberToWords only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,
E_USER_WARNING
);
return FALSE;
}
if ($number < 0) {
return $negative . self::convertNumberToWords(abs($number));
}
$string = $fraction = NULL;
if (strpos($number, '.') !== FALSE) {
list($number, $fraction) = explode('.', $number);
}
switch (TRUE) {
case $number < 21:
$string = $dictionary[$number];
break;
case $number < 100:
$tens = ((int) ($number / 10)) * 10;
$units = $number % 10;
$string = $dictionary[$tens];
if ($units) {
$string .= $hyphen . $dictionary[$units];
}
break;
case $number < 1000:
$hundreds = $number / 100;
$remainder = $number % 100;
$string = $dictionary[$hundreds] . ' ' . $dictionary[100];
if ($remainder) {
$string .= $conjunction . self::convertNumberToWords(abs($remainder));
}
break;
default:
$baseUnit = pow(1000, floor(log($number, 1000)));
$numBaseUnits = (int) ($number / $baseUnit);
$remainder = $number % $baseUnit;
$string = self::convertNumberToWords($numBaseUnits) . ' ' . $dictionary[$baseUnit];
if ($remainder) {
$string .= $remainder < 100 ? $conjunction : $separator;
$string .= self::convertNumberToWords($remainder);
}
break;
}
if (NULL !== $fraction && is_numeric($fraction)) {
$string .= $decimal;
$string .= $fraction . '/100';
}
return $string;
public static function convertNumberToWords($num) {
return ucwords(Numbers_Words::toWords($num));
}
}
......@@ -394,10 +394,11 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
$entityFileDAO->file_id = $fileID;
$entityFileDAO->save();
$contactID = CRM_Core_Session::getLoggedInContactID();
$activityID = civicrm_api3('Activity', 'create', [
'source_contact_id' => CRM_Core_Session::getLoggedInContactID(),
'source_contact_id' => $contactID,
'activity_type_id' => 'grant_payment',
'assignee_contact_id' => CRM_Core_Session::getLoggedInContactID(),
'assignee_contact_id' => $contactID,
'subject' => "Grant Payment",
'status_id' => 'Completed',
'priority_id' => 2,
......@@ -412,15 +413,8 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form {
),
);
CRM_Activity_BAO_Activity::create($params);
// download the zip file
CRM_Utils_System::setHttpHeader('Content-Type', 'application/zip');
CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename=' . CRM_Utils_File::cleanFileName(basename($zipFile)));
CRM_Utils_System::setHttpHeader('Content-Length', '' . filesize($uri));
ob_clean();
flush();
readfile($uri);
CRM_Utils_System::civiExit();
CRM_Core_Session::setStatus(ts('Please click the attached zip file to download the printed grant payments'));
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/activity', "action=view&reset=1&id=$activityID&cid=$contactID&context=activity&searchContext=activity"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment