Guest User

Untitled

a guest
Jun 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 53.04 KB | None | 0 0
  1. Public Class TaxReceiptHandler{
  2.  
  3. String ReceiptType,ReceiptSelect,rFilter;
  4. List <Tax_Receipt__c> lst_tax = new List <Tax_Receipt__c>();
  5.  
  6. Public Date DateToday {get;set;}
  7.  
  8. Public List <Donation_Receipts__c> lst_Receipt {get;set;}
  9. Public List<ReceiptHeaderWrap> lst_ReceiptHeaderwrap { get; set; }
  10. Public List<Tax_Receipt__c> lst_ReceiptHeader;
  11. Public List<Tax_Receipt__c> lst_RectDisplayAll {get;set;}
  12.  
  13. public List<Summary> Summaries { get; set; }
  14. Public Map<Integer,String> map_MonthNoDays;
  15. Public Map<Integer,String> map_Month;
  16. Set <String> rheaderId;
  17.  
  18. public Boolean refreshPage {get; set;}
  19.  
  20. Public String chosenYear{get;set;}
  21. Public String mailReportType {get;set;}
  22.  
  23. public TaxReceiptHandler() {
  24. }
  25.  
  26. public TaxReceiptHandler(ApexPages.StandardController controller) {
  27. refreshPage=false;
  28.  
  29.  
  30. }
  31.  
  32. public String getNewLine() {
  33. return '\n';
  34. }
  35.  
  36.  
  37. public String getPrintView() {
  38. return
  39. '<!--[if gte mso 9]>' +
  40. '<xml>' +
  41. '<w:WordDocument>' +
  42. '<w:View>Print</w:View>' +
  43. '<w:Zoom>100</w:Zoom>' +
  44. '<w:DoNotOptimizeForBrowser/>' +
  45. '</w:WordDocument>' +
  46. '</xml>' +
  47. '<![endif]>';
  48. }
  49.  
  50. public List<SelectOption> getRTypes() {
  51. List<SelectOption> options = new List<SelectOption>();
  52. options.add(new SelectOption('GWC','GWC'));
  53. options.add(new SelectOption('Trust','Trust'));
  54.  
  55. return options;
  56. }
  57.  
  58. Public String getReceiptDate() {
  59. Date recDate;
  60. String recMonth, recStringDate;
  61. recDate = System.Today();
  62.  
  63. if(recDate.Month() == 1){
  64. recMonth = 'January';
  65. }
  66. else if(recDate.Month() == 2){
  67. recMonth = 'February';
  68. }
  69. else if(recDate.Month() == 3){
  70. recMonth = 'March';
  71. }
  72. else if(recDate.Month() == 4){
  73. recMonth = 'April';
  74. }
  75. else if(recDate.Month() == 5){
  76. recMonth = 'May';
  77. }
  78. else if(recDate.Month() == 6){
  79. recMonth = 'June';
  80. }
  81. else if(recDate.Month() == 7){
  82. recMonth = 'July';
  83. }
  84. else if(recDate.Month() == 8){
  85. recMonth = 'August';
  86. }
  87. else if(recDate.Month() == 9){
  88. recMonth = 'September';
  89. }
  90. else if(recDate.Month() == 10){
  91. recMonth = 'October';
  92. }
  93. else if(recDate.Month() == 11){
  94. recMonth = 'November';
  95. }
  96. else if(recDate.Month() == 12){
  97. recMonth = 'December';
  98. }
  99. recStringDate= recDate.Day()+' '+recMonth +' '+recDate.Year();
  100. Return recStringDate;
  101.  
  102. }
  103.  
  104. public string getReceiptType(){
  105. return null;
  106. }
  107.  
  108.  
  109. public void setReceiptType(String ReceiptSelect){
  110. this.ReceiptSelect = ReceiptSelect;
  111. if(ReceiptSelect == ''){
  112. rFilter = Null;
  113. }
  114. if(ReceiptSelect == 'Trust'){
  115. rFilter = 'Trust';
  116. }
  117. if(ReceiptSelect == 'GWC'){
  118. rFilter = 'GWC';
  119. }
  120.  
  121. }
  122.  
  123.  
  124. Public List <Tax_Receipt__c> getAllSelectedTaxReceipt(){
  125.  
  126. String chosenYearstr,filterstr;
  127. Integer intYear;
  128. //chosenYearstr =ApexPages.currentPage().getParameters().get('year');
  129. //filterstr=ApexPages.currentPage().getParameters().get('filter');
  130. List <Tax_Receipt__c> lst_tax = new List <Tax_Receipt__c>();
  131. if(chosenYear != Null){
  132.  
  133. if(chosenYear != ''){
  134. intYear = Integer.valueof(chosenYear);
  135. mailReportType = rFilter;
  136. system.debug('***MR***'+ mailReportType);
  137.  
  138. lst_tax = [SELECT id,Contact__r.id,Amount_in_Words__c,Contact__r.Name,Certificate_Number__c,YearEnd__c,
  139. Contact__r.Postal_Street__c,Contact__r.Postal_Street_2__c,Contact__r.Postal_City__c,Contact__r.Postal_State_Province__c,Contact__r.Postal_Code__c,
  140. Financial_Year_Start__c,Financial_Year_End__c,Total_Receipt_Amount__c FROM Tax_Receipt__c WHERE IsClosed__c=:False AND FISCAL_YEAR(Financial_Year_End__c) =:intYear ];
  141. }
  142. }
  143. Return lst_tax;
  144.  
  145. }
  146.  
  147. Public void initDateMaps(){
  148. map_MonthNoDays = new Map<Integer,String>();
  149. map_MonthNoDays.put(1,'31');
  150. map_MonthNoDays.put(2,'28');
  151. map_MonthNoDays.put(3,'31');
  152. map_MonthNoDays.put(4,'30');
  153. map_MonthNoDays.put(5,'31');
  154. map_MonthNoDays.put(6,'30');
  155. map_MonthNoDays.put(7,'31');
  156. map_MonthNoDays.put(8,'31');
  157. map_MonthNoDays.put(9,'30');
  158. map_MonthNoDays.put(10,'31');
  159. map_MonthNoDays.put(11,'30');
  160. map_MonthNoDays.put(12,'31');
  161.  
  162.  
  163. map_Month = new Map<Integer,String>() ;
  164. map_Month.put(1,'January');
  165. map_Month.put(2,'February');
  166. map_Month.put(3,'March');
  167. map_Month.put(4,'April');
  168. map_Month.put(5,'May');
  169. map_Month.put(6,'June');
  170. map_Month.put(7,'July');
  171. map_Month.put(8,'August');
  172. map_Month.put(9,'September');
  173. map_Month.put(10,'October');
  174. map_Month.put(11,'November');
  175. map_Month.put(12,'December');
  176.  
  177. }
  178.  
  179.  
  180. Public void displayAllSumRecpt(){
  181.  
  182. lst_Receipt = new List<Donation_Receipts__c>();
  183. lst_Receipt = [Select id,Tax_Receipt__r.id from Donation_Receipts__c where Tax_Receipt__r.id =:apexpages.currentpage().getparameters().get('id')];
  184. initDateMaps();
  185. DisplaySumRec();
  186. SummaryReceipts();
  187.  
  188. system.debug('***ReceiptHeaderwrap_1****'+lst_ReceiptHeaderwrap);
  189. }
  190.  
  191.  
  192.  
  193. Public void DisplaySumRec(){
  194. lst_ReceiptHeader = new List<Tax_Receipt__c>();
  195. DateToday = system.Today();
  196. rheaderId = new Set <String>();
  197.  
  198. for(Donation_Receipts__c r:lst_Receipt){
  199. rheaderId.add(r.Tax_Receipt__r.id);
  200. }
  201. system.debug('**Don_Receipt**'+lst_Receipt+'**Set**'+rheaderId);
  202.  
  203. lst_ReceiptHeader = [select id,name,YearEnd__c,Date_closed__c,TodayDate__c,Total_Receipt_Amount__c,Year_end_Words__c,Year_Start_Words__c, Account__r.name,Account__r.Recordtype.name,
  204. Account__r.BillingCity, Account__r.BillingStreet,Certificate_Number__c, Account__r.BillingState,Account__r.BillingPostalCode,Contact_Donor_Id__c, Account_Donor_Id__c,
  205. Contact__r.Postal_Street__c,Contact__r.Postal_Street_2__c,Contact__r.Postal_City__c,Contact__r.Postal_State_Province__c,Contact__r.Postal_Code__c,Contact__c,Contact__r.Name,
  206. (select name from Donation_Receipts__r)
  207. from Tax_Receipt__c WHERE id in:rheaderId];
  208. system.debug('**lst_Receipt!!!!**'+lst_ReceiptHeader);
  209. }
  210.  
  211. public void SummaryReceipts(){
  212. List<receiptWrap> cw;
  213. lst_ReceiptHeaderwrap = new List<ReceiptHeaderWrap>();
  214. Map<String,String> map_TaxReceipt;
  215.  
  216. map_TaxReceipt = new Map<String,String>();
  217.  
  218. AggregateResult[] results = [SELECT Tax_Receipt__c, Calendar_Year(Date__c) year, Calendar_Month(Date__c) month , Sum (Donation_Amount__c) Quantity
  219. FROM Donation_Receipts__c WHERE Tax_Receipt__c in:rheaderId GROUP BY Tax_Receipt__c,Calendar_Year(Date__c),Calendar_Month(Date__c) ];
  220.  
  221. Summaries = new List<Summary>();
  222.  
  223. for (AggregateResult ar : results) {
  224. Summaries.add(new Summary(ar));
  225. }
  226.  
  227. system.debug('**lst_ReceiptHeader**'+lst_ReceiptHeader);
  228.  
  229. for(Tax_Receipt__c a:lst_ReceiptHeader){
  230. map_TaxReceipt.put(a.Name,a.Certificate_Number__c);
  231. }
  232.  
  233.  
  234. for(Tax_Receipt__c a:lst_ReceiptHeader){
  235. /*
  236. cw = new list<receiptWrap>();
  237. For(Summary s:Summaries){
  238.  
  239. s.ofullmonth = map_Month.get(s.oMonth) + ' ' + s.oyear;
  240.  
  241. if(s.oname == a.id){
  242. cw.add(new receiptWrap(s));
  243. }
  244.  
  245. }
  246. */
  247.  
  248. // lst_ReceiptHeaderwrap.add(new ReceiptHeaderWrap(a,false,cw));
  249. lst_ReceiptHeaderwrap.add(new ReceiptHeaderWrap(a,false));
  250.  
  251. }
  252.  
  253.  
  254. }
  255.  
  256.  
  257.  
  258.  
  259. Public List <Tax_Receipt__c> getAllCurrentTaxReceipt(){
  260.  
  261.  
  262. Integer intYear;
  263. List <Tax_Receipt__c> lst_tax = new List <Tax_Receipt__c>();
  264.  
  265. if(chosenYear != Null){
  266. system.debug('***Yearyyyyy***'+chosenYear);
  267. if(chosenYear != ''){
  268. intYear = Integer.valueof(chosenYear);
  269. lst_tax = [SELECT id,Year_end_Words__c,Year_Start_Words__c,Certificate_Number__c, Account__r.name,Account__r.Recordtype.name,
  270. Account__r.BillingCity, Account__r.BillingStreet, Account__r.BillingState,Account__r.BillingPostalCode,Contact_Donor_Id__c, Account_Donor_Id__c,
  271. Name,Contact__r.id,Financial_Year_Start__c,Financial_Year_End__c,IsClosed__c,Total_Receipt_Amount__c FROM Tax_Receipt__c WHERE FISCAL_YEAR(Financial_Year_End__c) =:intYear AND IsClosed__c=:False ];
  272. }
  273. system.debug('***lst_tax***'+lst_tax);
  274. }
  275. Return lst_tax;
  276.  
  277. }
  278.  
  279. Public List <Tax_Receipt__c> getAllCurrentClosedTaxReceipt(){
  280.  
  281.  
  282. Integer intYear;
  283. List <Tax_Receipt__c> lst_tax = new List <Tax_Receipt__c>();
  284.  
  285. if(chosenYear != null){
  286. if(chosenYear != ''){
  287. intYear = Integer.valueof(chosenYear);
  288. lst_tax = [SELECT id,Name,Contact__r.id,Certificate_Number__c,Account__r.Name,Financial_Year_Start__c,Financial_Year_End__c,IsClosed__c,Total_Receipt_Amount__c FROM Tax_Receipt__c WHERE FISCAL_YEAR(Financial_Year_End__c) =:intYear AND IsClosed__c=:True];
  289. }
  290. system.debug('***Year***'+chosenYear);
  291. }
  292. Return lst_tax;
  293.  
  294. }
  295.  
  296.  
  297. Public void DisplayAllCurrentreceipt(){
  298. Integer intYear;
  299.  
  300. if(chosenYear == ''){
  301.  
  302. ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Please type in the Receipt Year');
  303. ApexPages.addMessage(myMsg);
  304.  
  305. }
  306.  
  307. }
  308.  
  309. Public void CloseAllCurrentreceipt(){
  310.  
  311. Integer intYear;
  312.  
  313. List <Tax_Receipt__c> lst_tax = new List <Tax_Receipt__c>();
  314. if(chosenYear == ''){
  315.  
  316.  
  317. ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Please type in the Receipt Year');
  318. ApexPages.addMessage(myMsg);
  319.  
  320. }
  321. else{
  322.  
  323. if(chosenYear != null){
  324. if(chosenYear != ''){
  325. intYear = Integer.valueof(chosenYear);
  326. lst_tax = [SELECT id,Contact__r.id FROM Tax_Receipt__c WHERE FISCAL_YEAR(Financial_Year_End__c) =:intYear AND IsClosed__c=:false];
  327. for(Tax_Receipt__c tr:lst_tax){
  328. tr.IsClosed__c=true;
  329. tr.Date_closed__c = System.Today();
  330. }
  331. }
  332. }
  333. update lst_tax;
  334.  
  335. }
  336.  
  337. }
  338.  
  339.  
  340. Public List <Tax_Receipt__c> getIndivTaxReceipt(){
  341.  
  342. lst_tax = new List <Tax_Receipt__c>();
  343. lst_tax = [SELECT id,Contact__r.id,Contact__r.Name,Amount_in_Words__c,Certificate_Number__c,YearEnd__c,Contact__r.FirstName,
  344. Contact__r.Postal_Street__c,Contact__r.Postal_Street_2__c,Contact__r.Postal_City__c,Contact__r.Postal_State_Province__c,Contact__r.Postal_Code__c,Contact_Donor_Id__c, Account_Donor_Id__c,
  345. Financial_Year_Start__c,Financial_Year_End__c,Total_Receipt_Amount__c FROM Tax_Receipt__c
  346. WHERE id =:ApexPages.currentPage().getParameters().get('id')];
  347.  
  348. for(Tax_Receipt__c tr:lst_tax){
  349. // mailReportType = tr.Type__c;
  350. }
  351.  
  352. Return lst_tax;
  353.  
  354. }
  355.  
  356.  
  357.  
  358. Public PageReference PrintAllAggrCurrentreceipt(){
  359.  
  360. Integer intYear;
  361.  
  362. if(chosenYear == ''){
  363.  
  364. ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Please type in the Receipt Year');
  365. ApexPages.addMessage(myMsg);
  366. return null;
  367. }
  368. intYear = Integer.valueof(chosenYear);
  369. lst_Receipt = new List<Donation_Receipts__c>();
  370. lst_Receipt = [Select id,Tax_Receipt__r.id from Donation_Receipts__c where FISCAL_YEAR(Tax_Receipt__r.Financial_Year_End__c) =:intYear AND Tax_Receipt__r.IsClosed__c=:false];
  371. system.debug('###'+intYear+'###'+lst_Receipt);
  372. initDateMaps();
  373. DisplaySumRec();
  374. SummaryReceipts();
  375.  
  376. return new PageReference('/apex/PrintAllTRSum?year='+chosenYear+'&filter='+rFilter);
  377. }
  378.  
  379. Public PageReference PrintAllCurrentreceipt(){
  380.  
  381. Integer intYear;
  382.  
  383. if(chosenYear == ''){
  384.  
  385. ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Please type in the Receipt Year');
  386. ApexPages.addMessage(myMsg);
  387. return null;
  388. }
  389. intYear = Integer.valueof(chosenYear);
  390. lst_Receipt = new List<Donation_Receipts__c>();
  391. lst_Receipt = [Select id,Tax_Receipt__r.id from Donation_Receipts__c where FISCAL_YEAR(Tax_Receipt__r.Financial_Year_End__c) =:intYear AND Tax_Receipt__r.IsClosed__c=:false];
  392. system.debug('###'+intYear+'###'+lst_Receipt);
  393. initDateMaps();
  394. DisplaySumRec();
  395. SummaryReceipts();
  396.  
  397. return new PageReference('/apex/PrintAllTR?year='+chosenYear+'&filter='+rFilter);
  398. }
  399.  
  400.  
  401.  
  402. Public PageReference GenenerateIndividual(){
  403.  
  404. Id trId = ApexPages.currentPage().getParameters().get('id');
  405.  
  406. lst_tax = new List <Tax_Receipt__c>();
  407. lst_tax = [SELECT id,Contact__r.id,Contact_Donor_Id__c, Account_Donor_Id__c,Contact__r.LastName,Contact__r.FirstName,Receipt_Date__c,Certificate_Number__c,Contact__r.Postal_City__c ,Total_Receipt_Amount__c,Financial_Year_Start__c,Financial_Year_End__c,IsClosed__c FROM Tax_Receipt__c
  408. WHERE id =:ApexPages.currentPage().getParameters().get('id')];
  409.  
  410. for(Tax_Receipt__c tr:lst_tax){
  411. tr.IsClosed__c=True;
  412. // mailReportType = tr.Type__c;
  413. tr.Date_closed__c = system.Today();
  414. }
  415. update lst_tax;
  416.  
  417. refreshPage=true;
  418. system.debug('***ReceiptHeaderwrap_2****'+lst_ReceiptHeaderwrap);
  419. return null;
  420.  
  421. }
  422.  
  423.  
  424. //-----------------------RECEIPT INSERTS AND UPDATES
  425.  
  426.  
  427. public Static void returnDates(Map<String,Date> map_fiscalDate,Date OppDate,String AccType){
  428.  
  429. //Integer CurrentYear = datetime.now().year();
  430. Date StartDate, EndDate;
  431. Integer OppFiscalYear;
  432. Integer OppMonth;
  433. Integer Receiptfiscalyear;
  434. Integer FiscalYearStartMonth;
  435. String strstart = 'Start', strend = 'end';
  436.  
  437.  
  438. FiscalYearStartMonth = [select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;
  439. OppFiscalYear = OppDate.year();
  440. OppMonth = OppDate.month();
  441.  
  442. if(FiscalYearStartMonth > OppMonth){
  443. Receiptfiscalyear=OppFiscalYear-1;
  444. }
  445. if(FiscalYearStartMonth <= OppMonth){
  446. Receiptfiscalyear=OppFiscalYear;
  447. }
  448.  
  449.  
  450. if(AccType == 'Business'){
  451. if(FiscalYearStartMonth > OppMonth){
  452. Receiptfiscalyear=OppFiscalYear-1;
  453. }
  454. if(FiscalYearStartMonth <= OppMonth){
  455. Receiptfiscalyear=OppFiscalYear;
  456. }
  457. StartDate = date.newInstance(Receiptfiscalyear, FiscalYearStartMonth, 1);
  458. System.debug('**in business**'+StartDate);
  459. }
  460. else{
  461. if(FiscalYearStartMonth-1 > OppMonth){
  462. Receiptfiscalyear=OppFiscalYear-1;
  463. }
  464. if(FiscalYearStartMonth-1 <= OppMonth){
  465. Receiptfiscalyear=OppFiscalYear;
  466. }
  467. StartDate = date.newInstance(Receiptfiscalyear, FiscalYearStartMonth-1, 1);
  468. FiscalYearStartMonth = FiscalYearStartMonth-1;
  469. }
  470.  
  471. if(FiscalYearStartMonth-1 == 2){
  472. EndDate = date.newInstance(Receiptfiscalyear+1, FiscalYearStartMonth-1, 28);
  473. }
  474. else{
  475. EndDate = date.newInstance(Receiptfiscalyear+1, FiscalYearStartMonth-1, 30);
  476. }
  477. map_fiscalDate.put(strstart,StartDate);
  478. map_fiscalDate.put(strend,EndDate);
  479. system.debug('***111StartDate111***'+StartDate);
  480.  
  481. }
  482. Public static void updateDonationtoTaxReceipt(List <Opportunity> lst_opp){
  483.  
  484. List <Donation_Receipts__c> lst_tax = new List <Donation_Receipts__c>();
  485. Set<String> set_oppid = new set<String>();
  486. Map<String,Decimal> map_oppamount;
  487.  
  488. map_oppamount = new Map<String,Decimal>();
  489.  
  490. for(Opportunity o:lst_opp){
  491. map_oppamount.put(o.id,o.Amount);
  492. set_oppid.add(o.id);
  493. }
  494.  
  495. lst_tax = [SELECT id,Donation_Name__c FROM Donation_Receipts__c WHERE Donation_Name__r.id in: set_oppid];
  496. system.debug('**lst_tax**'+lst_tax);
  497. system.debug('**set_oppid**'+set_oppid);
  498.  
  499.  
  500. for(Donation_Receipts__c tr: lst_tax){
  501. tr.Donation_Amount__c = map_oppamount.get(tr.Donation_Name__c);
  502. }
  503. update lst_tax;
  504.  
  505. }
  506.  
  507. Public static void addDonationtoTaxReceipt(List <Opportunity> lst_opp){
  508.  
  509. List <Tax_Receipt__c> lst_tax = new List <Tax_Receipt__c>();
  510. List <Account> lst_Account = new List<Account>();
  511. List <OpportunityContactRole> Lst_ContactRole;
  512.  
  513. Map<String,String> map_ConRole;
  514. Map<String,String> map_AccRtype;
  515. Map<String,String> map_ContactReceipttrust;
  516.  
  517. Map<String,String> map_ReceiptDate;
  518. Map<String,Date> map_fiscalDate;
  519.  
  520. Map<String, String> map_Opptrust;
  521. Map<String,String> map_emptyrcptdate;
  522.  
  523. Map<String,Decimal> map_OppAmount;
  524.  
  525. Set<String> set_Accid = new set<String>();
  526. Set<String> set_Conid;
  527. Set<String> set_TRemptyopp;
  528. Set<String> set_oppId;
  529.  
  530. Opportunity ind_opp = new Opportunity();
  531. Donation_Receipts__c ind_rec;
  532.  
  533. Boolean taxList;
  534. Id taxreceipt, contactId, OppId;
  535. Date StartDate, EndDate;
  536. Integer OppFiscalYear,OppMonth,Receiptfiscalyear,FiscalYearStartMonth;
  537. String AccType = 'Business';
  538.  
  539. map_Opptrust = new Map<String, String>();
  540.  
  541. map_OppAmount = new Map<String,Decimal>();
  542. map_ReceiptDate = new Map<String,String>();
  543.  
  544.  
  545. FiscalYearStartMonth = [select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;
  546. set_oppId = new Set<String>();
  547. for(Opportunity o:lst_opp){
  548. set_Accid.add(o.AccountId);
  549. set_oppId.add(o.id);
  550. }
  551.  
  552. Lst_ContactRole = new List <OpportunityContactRole>([SELECT ContactId,OpportunityId FROM OpportunityContactRole where OpportunityId in:set_oppId]);
  553.  
  554. map_ConRole = new Map<String,String>();
  555. set_Conid = new Set<String>();
  556. for(OpportunityContactRole r:Lst_ContactRole){
  557. map_ConRole.put(r.OpportunityId,r.ContactId);
  558. set_Conid.add(r.ContactId);
  559. }
  560. system.debug('**MAP***'+map_ConRole);
  561. lst_Account = [SELECT id,RecordType.Name FROM Account WHERE id in:set_Accid];
  562. map_AccRtype = new Map<String,String>();
  563.  
  564. for(Account a: lst_Account){
  565. map_AccRtype.Put(a.id,a.RecordType.Name);
  566. }
  567.  
  568. system.debug('***map_AccRtype'+map_AccRtype);
  569.  
  570. for(Opportunity o:lst_opp){
  571. if(o.Donation_Status__c == 'Received' && o.ReceiptCount__c == 0){
  572.  
  573. map_OppAmount.put(o.id,o.Amount);
  574.  
  575. map_Opptrust.put(o.id,o.AccountId);
  576. system.debug('***map_Opptrust***'+map_Opptrust);
  577.  
  578.  
  579. OppFiscalYear = o.closedate.year();
  580. OppMonth = o.closedate.month();
  581. Receiptfiscalyear=OppFiscalYear;
  582.  
  583. if(FiscalYearStartMonth > OppMonth){
  584. Receiptfiscalyear=OppFiscalYear;
  585. }
  586. if(FiscalYearStartMonth <= OppMonth){
  587. Receiptfiscalyear=OppFiscalYear+1;
  588. }
  589.  
  590. /*
  591. if(map_AccRtype.get(o.Accountid) == 'Business Account'){
  592. else{
  593.  
  594.  
  595. if(FiscalYearStartMonth-1 > OppMonth){
  596. Receiptfiscalyear=OppFiscalYear;
  597. }
  598. if(FiscalYearStartMonth-1 <= OppMonth){
  599. Receiptfiscalyear=OppFiscalYear+1;
  600. }
  601. */
  602. map_ReceiptDate.put(o.id,string.valueof(Receiptfiscalyear));
  603. }
  604. }
  605.  
  606. System.Debug('***set_Accid***'+set_Accid);
  607. lst_tax = [SELECT id,Contact__r.id,AccountDate__c,Certificate_Number__c,Total_Receipt_Amount__c,Account__c,YearendYear__c,IsClosed__c FROM Tax_Receipt__c WHERE IsClosed__c=:false AND (Account__r.id in:set_Accid OR Contact__r.id in: set_Conid)];
  608.  
  609. taxList=false;
  610.  
  611. map_ContactReceipttrust = new Map<String,String> ();
  612. map_emptyrcptdate = new Map<String,String>();
  613.  
  614.  
  615. for(Tax_Receipt__c t:lst_tax){
  616. if(t.isClosed__c == false){
  617. map_ContactReceipttrust.put(t.AccountDate__c,t.id);
  618. map_emptyrcptdate.put(t.AccountDate__c,t.YearendYear__c);
  619. System.Debug('***Mapp***'+map_emptyrcptdate);
  620. }
  621. }
  622.  
  623. set_TRemptyopp = new Set<String>();
  624.  
  625. for(Opportunity o:lst_opp){
  626. if(map_ContactReceipttrust.get(o.AccountId) == Null){
  627. set_TRemptyopp.add(o.id);
  628. }
  629. }
  630. // map_ContactReceipttrust.clear();
  631.  
  632. String AccountDate;
  633. for(Opportunity o:lst_opp){
  634. if(o.Donation_Status__c == 'Received' && o.ReceiptCount__c == 0){
  635. // if(set_TRemptyopp.contains(o.id)){
  636. AccountDate='empty';
  637. if(map_ReceiptDate.get(o.id) != null){
  638. if(map_ConRole.get(o.id) == null){
  639. AccountDate = o.AccountId;
  640. }
  641. else{
  642. AccountDate = map_ConRole.get(o.id);
  643. }
  644. AccountDate = AccountDate.substring(0,15)+ map_ReceiptDate.get(o.id);
  645. }
  646. System.Debug('***AccountDate**'+ AccountDate + '***'+map_emptyrcptdate.get(AccountDate)+'**'+map_ReceiptDate.get(o.id));
  647. if(map_emptyrcptdate.get(AccountDate) != Null && map_ReceiptDate.get(o.id)== map_emptyrcptdate.get(AccountDate)){
  648. ind_rec = new Donation_Receipts__c();
  649. ind_rec.Donation_Amount__c = o.Amount;
  650. ind_rec.Donation_Name__c = o.id;
  651. ind_rec.Tax_Receipt__c = map_ContactReceipttrust.get(AccountDate);
  652. Insert ind_rec;
  653. }
  654.  
  655. if(map_emptyrcptdate.get(AccountDate) == Null || map_ReceiptDate.get(o.id) != map_emptyrcptdate.get(AccountDate)){
  656. map_fiscalDate = new Map<String,Date>();
  657.  
  658. returnDates(map_fiscalDate,o.closedate,AccType);
  659.  
  660. /*
  661. if(map_AccRtype.get(o.Accountid) == 'Business Account'){
  662.  
  663. returnDates(map_fiscalDate,o.closedate,AccType);
  664. }
  665. else{
  666. system.debug('**INDIVID**');
  667. AccType = 'Individual';
  668. returnDates(map_fiscalDate,o.closedate,AccType);
  669. }
  670. */
  671.  
  672. system.debug('***StartDate***'+StartDate);
  673.  
  674. Tax_Receipt__c ind_tax = new Tax_Receipt__c();
  675. system.debug('**MAP***'+map_ConRole.get(o.id));
  676. if(map_ConRole.get(o.id) == null){
  677. ind_tax.Account__c = o.AccountId;
  678. }
  679. else{
  680. ind_tax.Contact__c = map_ConRole.get(o.id);
  681. }
  682. ind_tax.Financial_Year_Start__c =map_fiscalDate.get('Start');
  683. ind_tax.Financial_Year_End__c = map_fiscalDate.get('end');
  684.  
  685. //----------to be adjusted for accumulated receipts
  686. //ind_tax.IsClosed__c = true;
  687. ind_tax.Date_closed__c = system.today();
  688. Insert ind_tax;
  689.  
  690. //adding new receipts to be mapped
  691.  
  692. map_ContactReceipttrust.put(ind_tax.AccountDate__c,ind_tax.id);
  693. map_emptyrcptdate.put(ind_tax.AccountDate__c,ind_tax.YearendYear__c);
  694.  
  695. ind_rec = new Donation_Receipts__c();
  696. ind_rec.Donation_Amount__c = o.Amount;
  697. ind_rec.Donation_Name__c = o.id;
  698. ind_rec.Tax_Receipt__c = ind_tax.id;
  699. Insert ind_rec;
  700. }
  701. // o.Receipt_Generated__c = true;
  702. // }
  703. }
  704. }
  705.  
  706. updateDonationtoTaxReceipt(lst_opp);
  707. }
  708.  
  709.  
  710. Public static void UpdateOpponCertificateDelete(List <Opportunity> lst_opp){
  711. Set<String> set_oppid = new Set<String>();
  712. Set<String> set_TCid = new Set<String>();
  713. //Set<String> map_TRtoTC;
  714. List <Donation_Receipts__c> lst_taxRec;
  715. List<Tax_Receipt__c> lst_taxCert;
  716.  
  717. for(Opportunity o:lst_opp){
  718. set_oppid.Add(o.id);
  719. }
  720.  
  721. lst_taxRec = new List <Donation_Receipts__c>([SELECT id,Donation_Name__c,Tax_Receipt__c FROM Donation_Receipts__c WHERE Donation_Name__c in: set_oppid]);
  722.  
  723. for(Donation_Receipts__c d:lst_taxRec){
  724. set_TCid.Add(d.Tax_Receipt__c);
  725. }
  726. system.debug('&&&'+lst_taxRec);
  727.  
  728. delete lst_taxRec;
  729.  
  730. lst_taxCert = new List<Tax_Receipt__c>([SELECT id FROM Tax_Receipt__c WHERE id in:set_TCid]);
  731. system.debug('&&&'+lst_taxCert);
  732.  
  733. lst_taxRec = new List <Donation_Receipts__c>([SELECT id,Donation_Name__c,Tax_Receipt__c FROM Donation_Receipts__c WHERE Tax_Receipt__c in: set_TCid]);
  734.  
  735. set_TCid.clear();
  736. for(Donation_Receipts__c d:lst_taxRec){
  737. set_TCid.Add(d.Tax_Receipt__c);
  738. }
  739.  
  740.  
  741. for(Tax_Receipt__c t:lst_taxCert){
  742. if(set_TCid.Contains(t.id) == false){
  743. delete t;
  744. }
  745. }
  746.  
  747. }
  748.  
  749.  
  750. Public static void UpdateOpponCertificateDelete(List<Tax_Receipt__c> lst_taxCert){
  751. Set<String> set_oppid = new Set<String>();
  752. Set<String> set_TCid = new Set<String>();
  753. List <Opportunity> lst_opp;
  754. List <Donation_Receipts__c> lst_taxRec;
  755.  
  756.  
  757. for(Tax_Receipt__c r:lst_taxCert){
  758. set_TCid.Add(r.id);
  759. }
  760.  
  761. lst_taxRec = new List <Donation_Receipts__c>([SELECT id,Donation_Name__c,Tax_Receipt__c FROM Donation_Receipts__c WHERE Tax_Receipt__c in: set_TCid]);
  762.  
  763. for(Donation_Receipts__c d:lst_taxRec){
  764. set_oppid.Add(d.Donation_Name__c);
  765. }
  766.  
  767. lst_opp = new List <Opportunity>([SELECT id,Donation_Status__c FROM Opportunity WHERE id in:set_oppid]);
  768.  
  769. for(Opportunity o:lst_opp){
  770. o.Donation_Status__c = 'Not Yet Received';
  771.  
  772.  
  773. }
  774. update lst_opp;
  775.  
  776. }
  777.  
  778.  
  779.  
  780. Public static void UpdateOpponReceiptDelete(List<Donation_Receipts__c> lst_taxRec){
  781. Set<String> set_oppid = new Set<String>();
  782. List <Opportunity> lst_opp;
  783.  
  784. for(Donation_Receipts__c d:lst_taxRec){
  785. set_oppid.Add(d.Donation_Name__c);
  786. }
  787.  
  788. lst_opp = new List <Opportunity>([SELECT id,Donation_Status__c FROM Opportunity WHERE id in:set_oppid]);
  789.  
  790. for(Opportunity o:lst_opp){
  791. o.Donation_Status__c = 'Not Yet Received';
  792.  
  793.  
  794. }
  795. update lst_opp;
  796.  
  797. }
  798.  
  799.  
  800. public static void AmountinWordsv2(List<Tax_Receipt__c> lst_taxRec){
  801.  
  802. String strfulltext,strDecimal,strNum,strAmtinWords,isZero;
  803. Boolean OneHthousand;
  804. Integer len,counter,intRctAmt,isTeen;
  805.  
  806. for(Tax_Receipt__c t: lst_taxRec){
  807. strfulltext = t.Total_Receipt_Amount__c.toPlainString();
  808. len = strfulltext.length()-3;
  809. strfulltext = strfulltext.substring(0, len);
  810. counter = 0;
  811. strAmtinWords = '';
  812. for(Integer tmplen=len;tmplen>0;tmplen--){
  813. strDecimal = strfulltext.substring(counter, len);
  814. intRctAmt = Integer.valueOf(strDecimal);
  815. system.debug('**intRctAmt**'+intRctAmt+'**strDecimal**'+strDecimal+'****'+strfulltext.substring(counter, counter+1));
  816. if(strfulltext.substring(counter, counter+1) == '0' && intRctAmt !=0){
  817. strDecimal = '';
  818. strNum = '';
  819. }
  820. else{
  821. if(intRctAmt>999999){
  822. system.debug('**Mill**'+intRctAmt);
  823. strDecimal = strDecimalPlace(intRctAmt);
  824. strNum = strfulltext.substring(counter, counter+1);
  825. intRctAmt = Integer.valueOf(strNum);
  826. strNum = strDecimalPlace(intRctAmt);
  827. }
  828. else if(intRctAmt<1000000 && intRctAmt>99999 ){
  829. system.debug('**intRctAmt100000**'+intRctAmt);
  830. strDecimal = strDecimalPlace(intRctAmt);
  831. strNum = strfulltext.substring(counter, counter+1);
  832. intRctAmt = Integer.valueOf(strNum);
  833. strNum = strDecimalPlace(intRctAmt);
  834. if(Integer.valueOf(strfulltext.substring(counter+1, counter+2))==0 && Integer.valueOf(strfulltext.substring(counter+2, counter+3))==0 ){
  835. strDecimal = strDecimal +' '+ 'Thousand';
  836.  
  837. }
  838. system.debug('*strNum**'+strNum+'**strDecimal*'+strDecimal);
  839. }
  840. else if(intRctAmt<100000 && intRctAmt>9999 ){
  841.  
  842. isZero = strfulltext.substring(1, 2);
  843. system.debug('**intRctAmt99999**'+intRctAmt+'*isZero*'+isZero);
  844. if(len>6 && isZero == '0'){
  845.  
  846. strDecimal = strDecimalPlace(intRctAmt);
  847. strNum = strfulltext.substring(counter, counter+2);
  848. intRctAmt = Integer.valueOf(strNum);
  849. strNum = strDecimalPlace(intRctAmt);
  850. if(Integer.valueOf(strfulltext.substring(counter+1, counter+2))!=0){
  851. if(Integer.valueOf(strfulltext.substring(counter, counter+1))!=1){
  852.  
  853. strNum = strNum + ' ' + strDecimalPlace(Integer.valueOf(strfulltext.substring(counter+1, counter+2)));
  854. }
  855. }
  856. }
  857. else if(len>5 && isZero != '0'){
  858. strDecimal = strDecimalPlace(intRctAmt);
  859. strNum = strfulltext.substring(counter, counter+2);
  860. intRctAmt = Integer.valueOf(strNum);
  861. strNum = 'and' +' '+strDecimalPlace(intRctAmt);
  862. system.debug('**Teen1**'+Integer.valueOf(strfulltext.substring(counter-1, counter)));
  863. if(Integer.valueOf(strfulltext.substring(counter+1, counter+2))!=0){
  864.  
  865. if(Integer.valueOf(strfulltext.substring(counter, counter+1))!=1){
  866.  
  867. strNum = strNum + ' ' + strDecimalPlace(Integer.valueOf(strfulltext.substring(counter+1, counter+2)));
  868. }
  869. }
  870. }
  871. else{
  872. strDecimal = strDecimalPlace(intRctAmt);
  873. strNum = strfulltext.substring(counter, counter+2);
  874. intRctAmt = Integer.valueOf(strNum);
  875. strNum = strDecimalPlace(intRctAmt);
  876. if(Integer.valueOf(strfulltext.substring(counter+1, counter+2))!=0){
  877.  
  878. if(Integer.valueOf(strfulltext.substring(counter, counter+1))!=1){
  879.  
  880. strNum = strNum + ' ' + strDecimalPlace(Integer.valueOf(strfulltext.substring(counter+1, counter+2)));
  881. }
  882. }
  883. }
  884.  
  885. }
  886. else if(intRctAmt<10000 && intRctAmt>999){
  887. system.debug('**intRctAmt1000**'+intRctAmt);
  888. isZero = strfulltext.substring(1, 2);
  889. if(len>6 && isZero == '0'){
  890.  
  891. strDecimal = strDecimalPlace(intRctAmt);
  892. strNum = strfulltext.substring(counter, counter+1);
  893. intRctAmt = Integer.valueOf(strNum);
  894. strNum = strDecimalPlace(intRctAmt);
  895. if(Integer.valueOf(strfulltext.substring(counter-1, counter))!=0 || Integer.valueOf(strfulltext.substring(counter-1, counter))==1){
  896. strNum = '';strDecimal = '';
  897. }
  898. }
  899. else{
  900.  
  901. strDecimal = strDecimalPlace(intRctAmt);
  902. strNum = strfulltext.substring(counter, counter+1);
  903. intRctAmt = Integer.valueOf(strNum);
  904. strNum = strDecimalPlace(intRctAmt);
  905. // system.debug('**Teen**'+Integer.valueOf(strfulltext.substring(counter-1, counter)));
  906. if(counter !=0){
  907. if(Integer.valueOf(strfulltext.substring(counter-1, counter))!=0 || Integer.valueOf(strfulltext.substring(counter-1, counter))==1){
  908. strNum = '';strDecimal = '';
  909. }
  910. }
  911. }
  912. }
  913. else if(intRctAmt<1000 && intRctAmt>99){
  914. system.debug('**intRctAmt100**'+intRctAmt);
  915. strDecimal = strDecimalPlace(intRctAmt);
  916. strNum = strfulltext.substring(counter, counter+1);
  917. intRctAmt = Integer.valueOf(strNum);
  918. strNum = strDecimalPlace(intRctAmt);
  919.  
  920. }
  921. else if(intRctAmt<100 && intRctAmt>19){
  922. system.debug('**intRctAmt50**'+intRctAmt);
  923. if(len>2){
  924. strDecimal = 'and' +' '+ strDecimalPlace(intRctAmt);
  925. strNum = strfulltext.substring(counter+1, counter+2);
  926. intRctAmt = Integer.valueOf(strNum);
  927. strNum = strDecimalPlace(intRctAmt);
  928. if(intRctAmt !=0) {
  929. strDecimal = strDecimal + ' ' + strNum;
  930. }
  931. strNum = '';
  932. }
  933. else{
  934. strDecimal = strDecimalPlace(intRctAmt);
  935. strNum = strfulltext.substring(counter+1, counter+2);
  936. intRctAmt = Integer.valueOf(strNum);
  937. strNum = strDecimalPlace(intRctAmt);
  938. if(intRctAmt !=0) {
  939. strDecimal = strDecimal + ' ' + strNum;
  940. }
  941. strNum = '';
  942. }
  943. }
  944. else if(intRctAmt<20 && intRctAmt>9){
  945. system.debug('**intRctAmt50**'+intRctAmt);
  946. if(len>3){
  947. strDecimal = 'and' +' '+ strDecimalPlace(intRctAmt);
  948. strNum = strfulltext.substring(counter+1, counter+2);
  949. strNum = '';
  950. }
  951. else{
  952. strDecimal = strDecimalPlace(intRctAmt);
  953. strNum = strfulltext.substring(counter+1, counter+2);
  954. strNum = '';
  955. }
  956. }
  957. else if(intRctAmt<10 ){
  958. system.debug('**intRctAmt9**'+intRctAmt);
  959. if(len>3){
  960. strDecimal = '';
  961. strNum = strfulltext.substring(counter, counter+1);
  962. intRctAmt = Integer.valueOf(strNum);
  963. strNum = 'and' +' '+strDecimalPlace(intRctAmt);
  964. if(Integer.valueOf(strfulltext.substring(counter-1, counter))!=0 || intRctAmt ==0) {
  965. strNum = '';
  966. }
  967. }
  968. else{
  969. strDecimal = '';
  970. strNum = strfulltext.substring(counter, counter+1);
  971. intRctAmt = Integer.valueOf(strNum);
  972. strNum = strDecimalPlace(intRctAmt);
  973. if(counter != 0){
  974. if(Integer.valueOf(strfulltext.substring(counter-1, counter))!=0 || intRctAmt ==0){
  975. strNum = '';
  976. }
  977. }
  978. }
  979. }
  980. system.debug('*strNum**'+strNum+'**strDecimal*'+strDecimal);
  981. strAmtinWords = strAmtinWords+ ' ' + strNum + ' '+ strDecimal ;
  982. }
  983. counter++;
  984. }
  985. strAmtinWords = strAmtinWords + ' ' + 'Rand' + ' ' + 'and';
  986.  
  987. //cents
  988.  
  989. strfulltext = t.Total_Receipt_Amount__c.toPlainString();
  990. strNum = '';
  991. strDecimal = '';
  992. len = strfulltext.length();
  993. system.debug('* strfulltext**'+ strfulltext+'**len*'+len);
  994. isTeen = 2;
  995. counter = 0;
  996. for(Integer tmplen=2;tmplen>0;tmplen--){
  997. isTeen++;
  998. if(isTeen != 1){
  999. strDecimal = strfulltext.substring(len-tmplen, len);
  1000. system.debug('* strDecimal**'+strDecimal);
  1001. intRctAmt = Integer.valueOf(strDecimal);
  1002. if(intRctAmt>19 && intRctAmt != 0 ){
  1003. strDecimal = strDecimalPlace(intRctAmt);
  1004. intRctAmt = Integer.valueOf(strfulltext.substring(len-1, len));
  1005. strNum = strDecimalPlace(intRctAmt);
  1006. isTeen = 0;
  1007. }
  1008. else if(intRctAmt<20 && intRctAmt>9 ){
  1009. strDecimal = strDecimalPlace(intRctAmt);
  1010. isTeen = 0;
  1011. }
  1012. else {
  1013. strDecimal = '';
  1014. }
  1015.  
  1016. if(intRctAmt<10){
  1017.  
  1018. if(counter == 0){
  1019. strNum = '';
  1020. }
  1021. else{
  1022. strNum = strfulltext.substring(len-1, len);
  1023. intRctAmt = Integer.valueOf(strNum);
  1024. strNum = strDecimalPlace(intRctAmt);
  1025. }
  1026. }
  1027. strAmtinWords = strAmtinWords + ' '+ strNum + ' '+ strDecimal ;
  1028. counter++;
  1029. }
  1030. }
  1031. strAmtinWords = strAmtinWords + ' ' + 'cents';
  1032. t.Amount_in_Words__c = strAmtinWords;
  1033. }
  1034. }
  1035.  
  1036. public static void AmountinWordsIndividual(List<Donation_Receipts__c> lst_taxRec){
  1037.  
  1038. String strfulltext,strDecimal,strNum,strAmtinWords,isZero;
  1039. Boolean OneHthousand;
  1040. Integer len,counter,intRctAmt,isTeen;
  1041.  
  1042. for(Donation_Receipts__c t: lst_taxRec){
  1043. strfulltext = t.Donation_Amount__c.toPlainString();
  1044. len = strfulltext.length()-3;
  1045. strfulltext = strfulltext.substring(0, len);
  1046. counter = 0;
  1047. strAmtinWords = '';
  1048. for(Integer tmplen=len;tmplen>0;tmplen--){
  1049. strDecimal = strfulltext.substring(counter, len);
  1050. intRctAmt = Integer.valueOf(strDecimal);
  1051. system.debug('**intRctAmt**'+intRctAmt+'**strDecimal**'+strDecimal+'****'+strfulltext.substring(counter, counter+1));
  1052. if(strfulltext.substring(counter, counter+1) == '0' && intRctAmt !=0){
  1053. strDecimal = '';
  1054. strNum = '';
  1055. }
  1056. else{
  1057. if(intRctAmt>999999){
  1058. system.debug('**Mill**'+intRctAmt);
  1059. strDecimal = strDecimalPlace(intRctAmt);
  1060. strNum = strfulltext.substring(counter, counter+1);
  1061. intRctAmt = Integer.valueOf(strNum);
  1062. strNum = strDecimalPlace(intRctAmt);
  1063. }
  1064. else if(intRctAmt<1000000 && intRctAmt>99999 ){
  1065. system.debug('**intRctAmt100000**'+intRctAmt);
  1066. strDecimal = strDecimalPlace(intRctAmt);
  1067. strNum = strfulltext.substring(counter, counter+1);
  1068. intRctAmt = Integer.valueOf(strNum);
  1069. strNum = strDecimalPlace(intRctAmt);
  1070. if(Integer.valueOf(strfulltext.substring(counter+1, counter+2))==0 && Integer.valueOf(strfulltext.substring(counter+2, counter+3))==0 ){
  1071. strDecimal = strDecimal+' '+ 'Thousand';
  1072. }
  1073. system.debug('*strNum**'+strNum+'**strDecimal*'+strDecimal);
  1074. }
  1075. else if(intRctAmt<100000 && intRctAmt>9999 ){
  1076.  
  1077. isZero = strfulltext.substring(1, 2);
  1078. system.debug('**intRctAmt99999**'+intRctAmt+'*isZero*'+isZero);
  1079. if(len>6 && isZero == '0'){
  1080.  
  1081. strDecimal = strDecimalPlace(intRctAmt);
  1082. strNum = strfulltext.substring(counter, counter+2);
  1083. intRctAmt = Integer.valueOf(strNum);
  1084. strNum = strDecimalPlace(intRctAmt);
  1085. if(Integer.valueOf(strfulltext.substring(counter+1, counter+2))!=0){
  1086. if(Integer.valueOf(strfulltext.substring(counter, counter+1))!=1){
  1087.  
  1088. strNum = strNum + ' ' + strDecimalPlace(Integer.valueOf(strfulltext.substring(counter+1, counter+2)));
  1089. }
  1090. }
  1091. }
  1092. else if(len>5 && isZero != '0'){
  1093. strDecimal = strDecimalPlace(intRctAmt);
  1094. strNum = strfulltext.substring(counter, counter+2);
  1095. intRctAmt = Integer.valueOf(strNum);
  1096. strNum = 'and' +' '+strDecimalPlace(intRctAmt);
  1097. system.debug('**Teen1**'+Integer.valueOf(strfulltext.substring(counter-1, counter)));
  1098. if(Integer.valueOf(strfulltext.substring(counter+1, counter+2))!=0){
  1099.  
  1100. if(Integer.valueOf(strfulltext.substring(counter, counter+1))!=1){
  1101.  
  1102. strNum = strNum + ' ' + strDecimalPlace(Integer.valueOf(strfulltext.substring(counter+1, counter+2)));
  1103. }
  1104. }
  1105. }
  1106. else{
  1107. strDecimal = strDecimalPlace(intRctAmt);
  1108. strNum = strfulltext.substring(counter, counter+2);
  1109. intRctAmt = Integer.valueOf(strNum);
  1110. strNum = strDecimalPlace(intRctAmt);
  1111. if(Integer.valueOf(strfulltext.substring(counter+1, counter+2))!=0){
  1112.  
  1113. if(Integer.valueOf(strfulltext.substring(counter, counter+1))!=1){
  1114.  
  1115. strNum = strNum + ' ' + strDecimalPlace(Integer.valueOf(strfulltext.substring(counter+1, counter+2)));
  1116. }
  1117. }
  1118. }
  1119.  
  1120. }
  1121. else if(intRctAmt<10000 && intRctAmt>999){
  1122. system.debug('**intRctAmt1000**'+intRctAmt);
  1123. isZero = strfulltext.substring(1, 2);
  1124. if(len>6 && isZero == '0'){
  1125.  
  1126. strDecimal = strDecimalPlace(intRctAmt);
  1127. strNum = strfulltext.substring(counter, counter+1);
  1128. intRctAmt = Integer.valueOf(strNum);
  1129. strNum = strDecimalPlace(intRctAmt);
  1130. if(Integer.valueOf(strfulltext.substring(counter-1, counter))!=0 || Integer.valueOf(strfulltext.substring(counter-1, counter))==1){
  1131. strNum = '';strDecimal = '';
  1132. }
  1133. }
  1134. else{
  1135.  
  1136. strDecimal = strDecimalPlace(intRctAmt);
  1137. strNum = strfulltext.substring(counter, counter+1);
  1138. intRctAmt = Integer.valueOf(strNum);
  1139. strNum = strDecimalPlace(intRctAmt);
  1140. // system.debug('**Teen**'+Integer.valueOf(strfulltext.substring(counter-1, counter)));
  1141. if(counter !=0){
  1142. if(Integer.valueOf(strfulltext.substring(counter-1, counter))!=0 || Integer.valueOf(strfulltext.substring(counter-1, counter))==1){
  1143. strNum = '';strDecimal = '';
  1144. }
  1145. }
  1146. }
  1147. }
  1148. else if(intRctAmt<1000 && intRctAmt>99){
  1149. system.debug('**intRctAmt100**'+intRctAmt);
  1150. strDecimal = strDecimalPlace(intRctAmt);
  1151. strNum = strfulltext.substring(counter, counter+1);
  1152. intRctAmt = Integer.valueOf(strNum);
  1153. strNum = strDecimalPlace(intRctAmt);
  1154.  
  1155. }
  1156. else if(intRctAmt<100 && intRctAmt>19){
  1157. system.debug('**intRctAmt50**'+intRctAmt);
  1158. if(len>2){
  1159. strDecimal = 'and' +' '+ strDecimalPlace(intRctAmt);
  1160. strNum = strfulltext.substring(counter+1, counter+2);
  1161. intRctAmt = Integer.valueOf(strNum);
  1162. strNum = strDecimalPlace(intRctAmt);
  1163. if(intRctAmt !=0) {
  1164. strDecimal = strDecimal + ' ' + strNum;
  1165. }
  1166. strNum = '';
  1167. }
  1168. else{
  1169. strDecimal = strDecimalPlace(intRctAmt);
  1170. strNum = strfulltext.substring(counter+1, counter+2);
  1171. intRctAmt = Integer.valueOf(strNum);
  1172. strNum = strDecimalPlace(intRctAmt);
  1173. if(intRctAmt !=0) {
  1174. strDecimal = strDecimal + ' ' + strNum;
  1175. }
  1176. strNum = '';
  1177. }
  1178. }
  1179. else if(intRctAmt<20 && intRctAmt>9){
  1180. system.debug('**intRctAmt50**'+intRctAmt);
  1181. if(len>3){
  1182. strDecimal = 'and' +' '+ strDecimalPlace(intRctAmt);
  1183. strNum = strfulltext.substring(counter+1, counter+2);
  1184. strNum = '';
  1185. }
  1186. else{
  1187. strDecimal = strDecimalPlace(intRctAmt);
  1188. strNum = strfulltext.substring(counter+1, counter+2);
  1189. strNum = '';
  1190. }
  1191. }
  1192. else if(intRctAmt<10 ){
  1193. system.debug('**intRctAmt9**'+intRctAmt);
  1194. if(len>3){
  1195. strDecimal = '';
  1196. strNum = strfulltext.substring(counter, counter+1);
  1197. intRctAmt = Integer.valueOf(strNum);
  1198. strNum = 'and' +' '+strDecimalPlace(intRctAmt);
  1199. if(Integer.valueOf(strfulltext.substring(counter-1, counter))!=0 || intRctAmt ==0) {
  1200. strNum = '';
  1201. }
  1202. }
  1203. else{
  1204. strDecimal = '';
  1205. strNum = strfulltext.substring(counter, counter+1);
  1206. intRctAmt = Integer.valueOf(strNum);
  1207. strNum = strDecimalPlace(intRctAmt);
  1208. if(counter != 0){
  1209. if(Integer.valueOf(strfulltext.substring(counter-1, counter))!=0 || intRctAmt ==0){
  1210. strNum = '';
  1211. }
  1212. }
  1213. }
  1214. }
  1215. system.debug('*strNum**'+strNum+'**strDecimal*'+strDecimal);
  1216. strAmtinWords = strAmtinWords+ ' ' + strNum + ' '+ strDecimal ;
  1217. }
  1218. counter++;
  1219. }
  1220. strAmtinWords = strAmtinWords + ' ' + 'Rand' + ' ' + 'and';
  1221.  
  1222. //cents
  1223.  
  1224. strfulltext = t.Donation_Amount__c.toPlainString();
  1225. strNum = '';
  1226. strDecimal = '';
  1227. len = strfulltext.length();
  1228. system.debug('* strfulltext**'+ strfulltext+'**len*'+len);
  1229. isTeen = 2;
  1230. counter = 0;
  1231. for(Integer tmplen=2;tmplen>0;tmplen--){
  1232. isTeen++;
  1233. if(isTeen != 1){
  1234. strDecimal = strfulltext.substring(len-tmplen, len);
  1235. system.debug('* strDecimal**'+strDecimal);
  1236. intRctAmt = Integer.valueOf(strDecimal);
  1237. if(intRctAmt>19 && intRctAmt != 0 ){
  1238. strDecimal = strDecimalPlace(intRctAmt);
  1239. intRctAmt = Integer.valueOf(strfulltext.substring(len-1, len));
  1240. strNum = strDecimalPlace(intRctAmt);
  1241. isTeen = 0;
  1242. }
  1243. else if(intRctAmt<20 && intRctAmt>9 ){
  1244. strDecimal = strDecimalPlace(intRctAmt);
  1245. isTeen = 0;
  1246. }
  1247. else {
  1248. strDecimal = '';
  1249. }
  1250.  
  1251. if(intRctAmt<10){
  1252.  
  1253. if(counter == 0){
  1254. strNum = '';
  1255. }
  1256. else{
  1257. strNum = strfulltext.substring(len-1, len);
  1258. intRctAmt = Integer.valueOf(strNum);
  1259. strNum = strDecimalPlace(intRctAmt);
  1260. }
  1261. }
  1262. strAmtinWords = strAmtinWords + ' '+ strNum + ' '+ strDecimal ;
  1263. counter++;
  1264. }
  1265. }
  1266. strAmtinWords = strAmtinWords + ' ' + 'cents';
  1267. t.Amount_in_Words__c = strAmtinWords;
  1268. }
  1269.  
  1270.  
  1271. }
  1272.  
  1273.  
  1274. Public static String strDecimalPlace(Integer intPlace){
  1275.  
  1276. String decimalValue;
  1277. system.debug('**intPlace*'+intPlace);
  1278.  
  1279. String numberValue;
  1280.  
  1281. if(intPlace == 0){
  1282. decimalValue = 'Zero';
  1283. return decimalValue;
  1284. }
  1285. if(intPlace == 1){
  1286. decimalValue = 'One';
  1287. return decimalValue;
  1288. }
  1289. if(intPlace == 2){
  1290. decimalValue = 'Two';
  1291. return decimalValue;
  1292. }
  1293. if(intPlace == 3){
  1294. decimalValue = 'Three';
  1295. return decimalValue;
  1296. }
  1297. if(intPlace == 4){
  1298. decimalValue = 'Four';
  1299. return decimalValue;
  1300. }
  1301. if(intPlace == 5){
  1302. decimalValue = 'Five';
  1303. return decimalValue;
  1304. }
  1305. if(intPlace == 6){
  1306. decimalValue = 'Six';
  1307. return decimalValue;
  1308. }
  1309. if(intPlace == 7){
  1310. decimalValue = 'Seven';
  1311. return decimalValue;
  1312. }
  1313. if(intPlace == 8){
  1314. decimalValue = 'Eight';
  1315. return decimalValue;
  1316. }
  1317.  
  1318. if(intPlace == 9){
  1319. decimalValue = 'Nine';
  1320. return decimalValue;
  1321. }
  1322.  
  1323. if(intPlace == 10){
  1324. decimalValue = 'Ten';
  1325. return decimalValue;
  1326. }
  1327. if(intPlace == 11){
  1328. decimalValue = 'Eleven';
  1329. return decimalValue;
  1330. }
  1331. if(intPlace == 12){
  1332. decimalValue = 'Twelve';
  1333. return decimalValue;
  1334. }
  1335. if(intPlace == 13){
  1336. decimalValue = 'Thirteen';
  1337. return decimalValue;
  1338. }
  1339. if(intPlace == 14){
  1340. decimalValue = 'Fourteen';
  1341. return decimalValue;
  1342. }
  1343. if(intPlace == 15){
  1344. decimalValue = 'Fifteen';
  1345. return decimalValue;
  1346. }
  1347. if(intPlace == 16){
  1348. decimalValue = 'Sixteen';
  1349. return decimalValue;
  1350. }
  1351. if(intPlace == 17){
  1352. decimalValue = 'Seventeen';
  1353. return decimalValue;
  1354. }
  1355. if(intPlace == 18){
  1356. decimalValue = 'Eighteen';
  1357. return decimalValue;
  1358. }
  1359. if(intPlace == 19){
  1360. decimalValue = 'Nineteen';
  1361. return decimalValue;
  1362. }
  1363.  
  1364.  
  1365. if(intPlace >= 20 && intPlace < 30){
  1366. decimalValue = 'Twenty';
  1367. return decimalValue;
  1368. }
  1369. if(intPlace >= 30 && intPlace < 40){
  1370. decimalValue = 'Thirty';
  1371. return decimalValue;
  1372. }
  1373. if(intPlace >= 40 && intPlace < 50){
  1374. decimalValue = 'Forty';
  1375. return decimalValue;
  1376. }
  1377. if(intPlace >= 50 && intPlace < 60){
  1378. decimalValue = 'Fifty';
  1379. return decimalValue;
  1380. }
  1381. if(intPlace >= 60 && intPlace < 70){
  1382. decimalValue = 'Sixty';
  1383. return decimalValue;
  1384. }
  1385. if(intPlace >= 70 && intPlace < 80){
  1386. decimalValue = 'Seventy';
  1387. return decimalValue;
  1388. }
  1389. if(intPlace >= 80 && intPlace < 90){
  1390. decimalValue = 'Eighty';
  1391. return decimalValue;
  1392. }
  1393. if(intPlace >= 90 && intPlace < 100){
  1394. decimalValue = 'Ninety';
  1395. return decimalValue;
  1396. }
  1397. if(intPlace >= 100 && intPlace <= 999){
  1398. decimalValue = 'Hundred';
  1399. return decimalValue;
  1400. }
  1401. if(intPlace >= 1000 && intPlace < 100000){
  1402. decimalValue = 'Thousand';
  1403. return decimalValue;
  1404. }
  1405. if(intPlace > 99999 && intPlace < 1000000){
  1406. decimalValue = 'Hundred';
  1407. return decimalValue;
  1408. }
  1409.  
  1410. if(intPlace > 999999){
  1411. decimalValue = 'Million';
  1412. return decimalValue;
  1413. }
  1414.  
  1415. return null;
  1416. }
  1417.  
  1418. public class ReceiptHeaderWrap{
  1419. public Tax_Receipt__c oTaxReceipt{get;set;}
  1420. public boolean isSelected{get;set;}
  1421. // public List<receiptWrap> receiptset{get;set;}
  1422. public ReceiptHeaderWrap(Tax_Receipt__c a,boolean b /* List<receiptWrap> c */ ){
  1423. oTaxReceipt=a;
  1424. isSelected=b;
  1425. // receiptset=c;
  1426. }
  1427. }
  1428.  
  1429. public class receiptWrap{
  1430. public Donation_Receipts__c oReceipt{get;set;}
  1431. public boolean isSelected{get;set;}
  1432. public Summary oSummary {get; set;}
  1433. public receiptWrap(Summary a){
  1434. oSummary=a;
  1435. isSelected=false;
  1436. }
  1437. }
  1438.  
  1439. public class Summary {
  1440. public Decimal oQuantity { get; private set; }
  1441. public String oName { get; private set; }
  1442. public Decimal oYear { get; private set; }
  1443. public Integer oMonth { get; private set; }
  1444. public String ofullmonth {get; private set;}
  1445.  
  1446. public Summary(AggregateResult ar) {
  1447. oQuantity = (Decimal) ar.get('Quantity');
  1448. oName = (String) ar.get('Tax_Receipt__c');
  1449. oYear = (Decimal) ar.get('Year');
  1450. oMonth = (Integer) ar.get('Month');
  1451. }
  1452. }
  1453.  
  1454.  
  1455. }
Add Comment
Please, Sign In to add comment