=====================================================================
<apex:page standardController="ComplaintLineItem__c" extensions="InvoiceLineItem_Cls" recordSetVar="Complaint Line Items" id="pageid">
<script type="text/javascript">
function doCheckboxChange(cb,itemId){
if(cb.checked==true){
// alert(itemId);
aSelectItem(itemId);
}
else{
aDeselectItem(itemId);
}
}
</script>
<script type="text/javascript">
function callValidate() {
btnValidate.click();
}
</script>
<apex:form id="frmid">
<apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="NONE" status="loader">
<apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
</apex:actionFunction>
<apex:actionFunction name="save_Cate" action="{!save_categary}" rerender="NONE" status="loader" >
<apex:param name="Invoice_catId" value="" assignTo="{!Invoice_id}"/>
<apex:param name="Category_catId" value="" assignTo="{!category_id}"/>
</apex:actionFunction>
<apex:actionFunction name="aDeselectItem" action="{!doDeselectItem}" rerender="NONE" status="loader">
<apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
</apex:actionFunction>
<apex:pageBlock title="Find SAP Invoice Number:" id="searchBlock">
<table id="tableid">
<tr>
<td>
<apex:outputLabel value="SAP Invoice Number"/>
</td>
<td>
<apex:selectList value="{!SAPNumber}" title="SAP Invoice Number" size="1">
<apex:selectOptions value="{!SAPInvoiceNumber}"/>
</apex:selectList>
</td>
<td> Search Content </td>
<td>
<apex:inputText id="txtSAPNumber" value="{!txtSAPNo}" onkeyup="callValidate();" />
</td>
<td>
<apex:outputLabel value="Filter On Case CustomerNo "/>
<apex:inputCheckbox value="{!CusNo}" id="chkCustomer"/>
</td>
<td>
<apex:commandButton value="Search" action="{!search}"/>
</td>
</tr>
</table>
</apex:pageBlock>
<apex:pageMessages id="msg" />
<script>
var btnValidate = document.getElementById("{!$Component.validateBtn}");
</script>
<apex:pageBlock title="InvoiceLineItem Details " id="pb" >
<apex:actionstatus id="loader">
<apex:facet name="start">
<div class="waitingSearchDiv" id="sdebata_loader" style="background-color: #fbfbfb; height: 100%;opacity:0.65;width:100%;position: fixed;">
<div class="waitingHolder" style="top: 200px; left:600px; width: 91px; position: fixed;">
<img class="waitingImage" src="/img/loading.gif" title="Please Wait..." />
<span class="waitingDescription">Please wait...</span>
</div>
</div>
</apex:facet>
</apex:actionstatus>
<apex:pageBlockButtons >
<apex:commandButton value="Add Selected" action="{!processSelected}" />
<apex:commandButton value="Back" action="{!BackToParent}"/>
<apex:commandButton action="{!previous}" rendered="{!hasPrevious}" value="<" ></apex:commandButton>
<apex:commandButton action="{!next}" rendered="{!hasNext}" value=">" >
</apex:commandButton>
<apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!catInnerObj}" var="line" >
<apex:column headerValue="Select">
<apex:inputCheckbox value="{!line.isSelected}" onclick="doCheckboxChange(this,'{!line.cat.Id}')" />
</apex:column>
<apex:column headerValue="Name" value="{!line.cat.Name}"/>
<apex:column headerValue="SAP Invoice Number" value="{!line.cat.GE_LGT_EM_SAP_Invoice_Number__c}" />
<!-- <apex:column value="{!line.cat.GE_LGT_EM_Material__c}"/>-->
<apex:column value="{!line.cat.GE_LGT_EM_Material__r.GE_LGT_EM_SAP_MaterialNumber__c}"/>
<apex:column value="{!line.cat.GE_LGT_EM_InvoicedValue__c}"/>
<apex:column value="{!line.cat.GE_LGT_EM_Invoiced_Quantity__c}"/>
<!-- <apex:column value="{!line.cat.GE_LGT_EM_Material__c}"/> -->
<apex:column value="{!line.cat.GE_LGT_EM_Delivery_Plant__c}"/>
<apex:column headerValue="Category" >
<apex:inputField id="Case_Cate" value="{!line.cat.GE_LGT_EM_Category__c}" onchange="save_Cate('{!line.cat.Id}',this.value)" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
====================================================================
public with sharing class InvoiceLineItem_Cls {
//**** declaration parts Starts here ****
list<GE_LGT_EM_ComplaintLineItem__c>insertlist=new list<GE_LGT_EM_ComplaintLineItem__c>();
Id Caseid = System.currentPageReference().getParameters().get('id');
public boolean CusNo{get;set;}
public string Invoice_id{get;set;}
public string category_id{get;set;}
String strQuery;
String SAPNumber;
String txtSAPNo;
String innerQuery ='';
public Set<Id> selectedInvoiceIds;
Map<String, String> catgoryMap = new Map<String, String>();
public List<GE_LGT_EM_InvoiceLineItem__c> selectedInvoice1;
public String contextItem{get;set;}
public List<Case>AccCusid=new List<Case>();
//String accountids;
public string accountids {get;set;}
GE_LGT_EM_CustomIterable obj;
public list<GE_LGT_EM_CategoryInner> catInnerObj {get;set;}
public string sQuery;
//**** declaration parts End here****
//****constructor in onload page for getting records ****
public GE_LGT_EM_InvoiceLineItem_Cls(ApexPages.StandardSetController controller) {
Id Caseid = System.currentPageReference().getParameters().get('id');
AccCusid=[SELECT AccountId FROM Case where id=:Caseid];
for(Case accids:AccCusid)
accountids=accids.AccountId;
this.selectedInvoiceIds= new Set<Id>();
system.debug ('accountids' + accountids);
sQuery ='select id,Name,GE_LGT_EM_SAP_Invoice_Number__c,GE_LGT_EM_Invoiced_Price__c,GE_LGT_EM_InvoicedValue__c,GE_LGT_EM_Invoiced_Quantity__c,GE_LGT_EM_InvoiceHeaderNumber__c,GE_LGT_EM_Order_Number__c,GE_LGT_EM_Delivery_Plant__c,GE_LGT_EM_SAP_LineItemNumber__c,GE_LGT_EM_Category__c,GE_LGT_EM_Material__r.id,GE_LGT_EM_Material__r.GE_LGT_EM_SAP_MaterialNumber__c from GE_LGT_EM_InvoiceLineItem__c where id not in(SELECT GE_LGT_EM_Ref_InvoiceLineItem__c FROM GE_LGT_EM_ComplaintLineItem__c where GE_LGT_EM_CaseNumber__c='+'\''+Caseid+'\')' ;
system.debug('sQuery &*&*&*&*&* ' + sQuery);
obj = new GE_LGT_EM_CustomIterable(sQuery);
obj.setPageSize = 10;
next();
}
// ****handle item Selected****
public void doSelectItem(){
this.selectedInvoiceIds.add(this.contextItem);
system.debug('selectedInvoiceIdsjjjjjj '+selectedInvoiceIds);
}
//****handle item deselected****
public void doDeselectItem(){
this.selectedInvoiceIds.remove(this.contextItem);
}
// ****selected invoice list added into Wrapper class****
public List<GE_LGT_EM_InvoiceLineItem__c> getcatInnerObj(){
system.debug('getRecords--&&&---->'+obj.ListLineItemObj());
selectedInvoice1 =new List <GE_LGT_EM_InvoiceLineItem__c>();
for(GE_LGT_EM_CategoryInner selectinnerlist:obj.ListLineItemObj()) {
system.debug('selectinnerlist.cat %&%&%& ' +selectinnerlist.cat.Id);
if(this.selectedInvoiceIds.contains(selectinnerlist.cat.Id)){
selectedInvoice1.add(selectinnerlist.cat);
}
}
system.debug('selectedInvoice1-------->'+selectedInvoice1.size());
system.debug('selectedInvoiceIds $%$%$%$ '+selectedInvoiceIds.size());
return selectedInvoice1;
}
// ****Selected invoicelist insert into the complaintlineitem object****
public PageReference processSelected() {
integer counter=0;
list<GE_LGT_EM_ComplaintLineItem__c> ListLineItemCount=[SELECT GE_LGT_EM_Complaint_Reference_Number__c FROM GE_LGT_EM_ComplaintLineItem__c where GE_LGT_EM_CaseNumber__c=:Caseid and GE_LGT_EM_Complaint_Reference_Number__c !=null order by GE_LGT_EM_Complaint_Reference_Number__c desc limit 1];
id devRecordTypeId =Schema.SObjectType.GE_LGT_EM_ComplaintLineItem__c.getRecordTypeInfosByName().get('Complaint Line Items').getRecordTypeId();
for(GE_LGT_EM_ComplaintLineItem__c ar:ListLineItemCount){
counter= integer.valueof(ar.GE_LGT_EM_Complaint_Reference_Number__c);
}
system.debug('maxcountervalue-------->'+counter);
for(GE_LGT_EM_InvoiceLineItem__c InvObj:getcatInnerObj() ) {
if(counter==0){
counter=10;
}
else{
counter=counter+10;
}
GE_LGT_EM_ComplaintLineItem__c GELineItem = new GE_LGT_EM_ComplaintLineItem__c();
GELineItem.GE_LGT_EM_CaseNumber__c=Caseid;
GELineItem.RecordTypeId =devRecordTypeId;
GELineItem.GE_LGT_EM_Ref_InvoiceLineItem__c=InvObj.id ;
GELineItem.GE_LGT_EM_RequestedUnitPrice__c=InvObj.GE_LGT_EM_Invoiced_Price__c;
system.debug('catgoryMap.get(InvObj.id)v*&*&*& '+catgoryMap.get(InvObj.id));
GELineItem.GE_LGT_EM_Complaint_Reference_Number__c=counter;
GELineItem.GE_LGT_EM_Category__c=catgoryMap.get(InvObj.id);
GELineItem.GE_LGT_EM_Material_Number__c=InvObj.GE_LGT_EM_Material__r.id;
GELineItem.GE_LGT_EM_Plant__c=InvObj.GE_LGT_EM_Delivery_Plant__c;
insertlist.add(GELineItem);
system.debug('insertlist--->'+insertlist.size());
}
if(insertlist.size()>0 ){
insert insertlist;
PageReference reference= new PageReference('/'+Caseid);
reference.setRedirect(true);
return reference;
}
else{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Please select atleast one record'));
return null;
}
return null;
}
// ****when clicking on back button its going to parent page****
public PageReference BackToParent(){
PageReference reference= new PageReference('/'+Caseid);
reference.setRedirect(true);
return reference;
}
//*********** pagenation Start here********************
public Boolean hasNext {
get {
return obj.hasNext();
}
set;
}
// ****indicates whether there are more records before the current page set ****
public Boolean hasPrevious {
get {
return obj.hasPrevious();
}
set;
}
// ****returns the previous page of records****
public void previous() {
catInnerObj = obj.previous();
}
//**** returns the next page of records****
public void next() {
catInnerObj = obj.next();
}
// ****Selected records count****
public Integer getSelectedCount(){
return this.selectedInvoiceIds.size();
}
//************ End Pagenation******************
public String getSAPNumber() {
return SAPNumber;
}
public void setSAPNumber(String SAPNumber) {
this.SAPNumber= SAPNumber;
}
public String gettxtSAPNo(){
return txtSAPNo;
}
public void settxtSAPNo(String txtSAPNo){
this.txtSAPNo=txtSAPNo;
}
public List<SelectOption> getSAPInvoiceNumber() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Like','Like'));
options.add(new SelectOption('=','='));
return options;
}
//************** Search functionality starts here********************
public PageReference Search() {
String paraNo=getSAPNumber();
String varNo=gettxtSAPNo();
System.debug('paraNo------> '+paraNo);
System.debug('varNo------> '+varNo);
if((txtSAPNo==null || txtSAPNo=='') && CusNo==false){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Please enter SAP Invoice Number or check the CustomerNo Checkbox'));
return null;
}
strQuery='select id,Name,GE_LGT_EM_Material__r.GE_LGT_EM_SAP_MaterialNumber__c,GE_LGT_EM_InvoicedValue__c,GE_LGT_EM_Invoiced_Price__c,GE_LGT_EM_SAP_Invoice_Number__c,GE_LGT_EM_Invoiced_Quantity__c,GE_LGT_EM_InvoiceHeaderNumber__c,GE_LGT_EM_Order_Number__c,GE_LGT_EM_Category__c,GE_LGT_EM_SAP_LineItemNumber__c,GE_LGT_EM_Delivery_Plant__c,GE_LGT_EM_Material__r.id,GE_LGT_EM_InvoiceHeaderNumber__r.name,GE_LGT_EM_InvoiceHeaderNumber__r.GE_LGT_EM_CustomerName__c from GE_LGT_EM_InvoiceLineItem__c where';
System.debug('------>strQuery1'+strQuery);
if(getSAPNumber()=='Like' && txtSAPNo !='' && CusNo==false){
System.debug('Custo:'+CusNo);
strQuery=strQuery+' '+'GE_LGT_EM_SAP_Invoice_Number__c '+paraNo+'\''+varNo+'%'+'\'';
System.debug('SAP Invoice Number IN operator--->1:'+strQuery);
}
else if(getSAPNumber()=='Like' && txtSAPNo !='' && CusNo==True)
{
strQuery=strQuery+' '+'GE_LGT_EM_SAP_Invoice_Number__c '+paraNo+'\''+varNo+'%'+'\''+' and GE_LGT_EM_InvoiceHeaderNumber__r.GE_LGT_EM_CustomerName__c ='+'\''+accountids+'\'';
// strQuery=strQuery+' '+'GE_LGT_EM_SAP_Invoice_Number__c '+paraNo+' '+'('+varNo+')'+' ';
System.debug('SAP Invoice Number :'+strQuery);
}
else if(getSAPNumber()=='=' && txtSAPNo !='' && CusNo==True){
strQuery=strQuery+' '+'GE_LGT_EM_SAP_Invoice_Number__c '+paraNo+'\''+varNo+'\''+' and GE_LGT_EM_InvoiceHeaderNumber__r.GE_LGT_EM_CustomerName__c ='+'\''+accountids+'\'';
}
else if(getSAPNumber()=='=' && txtSAPNo !='' && CusNo==false){
strQuery=strQuery+' '+'GE_LGT_EM_SAP_Invoice_Number__c '+paraNo+'\''+varNo+'\'';
}
else if(txtSAPNo =='' && CusNo==True){
strQuery=strQuery+' GE_LGT_EM_InvoiceHeaderNumber__r.GE_LGT_EM_CustomerName__c ='+'\''+accountids+'\'';
system.debug('strQuery Account id ****' + strQuery);
}
if(txtSAPNo !='' || CusNo==True){
System.debug('Final Query String--->'+strQuery);
obj = new GE_LGT_EM_CustomIterable(strQuery);
obj.setPageSize = 10;
next();
}
SAPNumber='';
txtSAPNo='';
return null;
}
//************** Search functionality End here********************
// this method using for getting category values once event is onchanged
public void save_categary() {
catgoryMap.put(Invoice_id,category_id);
}
}
//***************************** End main class********************************
No comments:
Post a Comment