Advertisement
Guest User

FIN_ContRateFinancingProcess

a guest
Feb 25th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. package it.---.contabilita.plus.process;
  2.  
  3.  
  4. public class FIN_ContRateFinancingProcess implements IBusinessLogicFragment {
  5.  
  6. private static Logger log = (ServiceCore.getDMLogger()).retrieveLogger(FIN_ContRateFinancingProcess.class);
  7. private IDataModel data;
  8. private String trxName;
  9. private Integer ad_org_id;
  10. private Integer ad_client_id;
  11. private BigDecimal rateAmt;
  12. private Integer financingRateId;
  13. private Integer financingId;
  14. private Integer chargeId;
  15. private Integer projectId;
  16.  
  17. private final String tipoAddSoloInc = "SOLO_INC";
  18.  
  19. @Override
  20. public void init(IComposableBusinessLogic process, IDataModel params) {
  21. this.data = process.getSessionProps();
  22. this.trxName = process.get_TrxName();
  23. this.financingRateId = params.getInt(DMFINCEFinancingRate.COLUMNNAME_FINCE_FinancingRate_ID);
  24. this.ad_org_id = data.getInt("#" + DMFINCEFINANCING.COLUMNNAME_AD_Org_ID);
  25. this.ad_client_id = data.getInt("#" + DMFINCEFINANCING.COLUMNNAME_AD_Client_ID);
  26. this.rateAmt = params.getBigDecimal(DMFINCEFinancingRate.COLUMNNAME_FIN_FinancingAmtRate);
  27. this.financingId = params.getInteger(DMFINCEFINANCING.COLUMNNAME_FINCE_FINANCING_ID);
  28. this.chargeId = params.getInteger(DMFINCEFinancingRate.COLUMNNAME_C_Charge_ID);
  29. //this.projectId = params.getInteger(DMFINCEFinancingRate.columnname_c_project_id); C_PROJECT_ID non c'è nel data model
  30. }
  31.  
  32. @Override
  33. public String doIt() {
  34. String esito = "KO";
  35. if (financingRateId != null && financingRateId > 0) {
  36.  
  37. String tipoAddebito = getTipoAddebito();
  38. Integer bpartnerID = getBPartnerFromFinancing();
  39. Integer docTypeId = getDocTypeId(tipoAddebito);
  40. Integer accountID = getAccountId();
  41. java.sql.Timestamp dataIscrBil = getDataIscrBil();
  42.  
  43. if (tipoAddebito != null && tipoAddebito != "") {
  44. if (docTypeId != null && docTypeId > 0) {
  45. if (bpartnerID != null && bpartnerID > 0) {
  46. if (tipoAddSoloInc.equalsIgnoreCase(tipoAddebito)) { // Tipo
  47. // addebito
  48. // SOLO_INC
  49. try {
  50. // Builder che crea la Invoice
  51. IInvoiceBuilder i_ib = InvoiceBuilder.get(data, ad_org_id, bpartnerID, docTypeId,
  52. dataIscrBil, trxName); // interfaccia
  53. DMCInvoice invoice = i_ib.build();
  54.  
  55. invoice.save(trxName);
  56.  
  57. Integer invoiceID = invoice.getRecordID();
  58.  
  59. if (invoiceID != null && invoiceID > 0) {
  60. if (accountID != null && accountID > 0) {
  61.  
  62. setCInvoiceFK(invoiceID);
  63.  
  64.  
  65. // Builder che crea la InvoiceLine
  66. IInvoiceLineBuilder iLine_ib = InvoiceLineBuilder.get(data, invoice, trxName)
  67. .witAmt(rateAmt); // interfaccia
  68. DMCInvoiceLine invoiceLine = iLine_ib.build();
  69.  
  70.  
  71. if (projectId != null && projectId > 0) {
  72. invoiceLine.setC_Project_ID(projectId);
  73. }
  74.  
  75. if (chargeId != null && chargeId > 0) {
  76. invoiceLine.setC_Charge_ID(chargeId);
  77. }
  78.  
  79. invoiceLine.save(trxName);
  80. esito="OK";
  81. return esito;
  82.  
  83. }
  84. return esito;
  85. }
  86. return esito;
  87. } catch (Exception e) {
  88. log.log(Level.SEVERE, e.getLocalizedMessage(), e);
  89. throw new DataModelException(e);
  90. }
  91. }
  92. return esito;
  93. }
  94. return esito;
  95. }
  96. return esito;
  97. }
  98. return esito;
  99. }
  100. return esito;
  101. }
  102.  
  103.  
  104. //INSERIRE PIù TRY CATCH CON I VARI LOG
  105.  
  106. protected void setCInvoiceFK(Integer invoiceID) {
  107. IDataModel financing = ServiceCore.getDataModel(data, DMFINCEFINANCING.TableName,
  108. financingId, trxName);
  109. financing.setInt(DMFINCEFINANCING.COLUMNNAME_C_Invoice_ID, invoiceID);
  110. financing.getInt(DMFINCEFINANCING.COLUMNNAME_C_Invoice_ID);
  111. financing.save(trxName);
  112. }
  113.  
  114.  
  115.  
  116. private Integer getAccountId() {
  117.  
  118. IDataModel financing = ServiceCore.getDataModel(data, DMFINCEFINANCING.TableName, financingId, trxName);
  119. Integer accountId = financing.getInt(DMFINCEFINANCING.COLUMNNAME_FINCE_RegSrcFinancing_ID);
  120. return accountId;
  121. }
  122.  
  123.  
  124. private String getTipoAddebito() {
  125. String sql = "SELECT " + DMFINCEFINANCING.COLUMNNAME_FIN_FinancingTypeCharge + " FROM "
  126. + DMFINCEFINANCING.TableName + " WHERE " + DMFINCEFINANCING.COLUMNNAME_FINCE_FINANCING_ID + " = ?";
  127. String tipoAddebitoFin = DBUtils.getValue(trxName, sql, financingId);
  128. if (tipoAddebitoFin != null && tipoAddebitoFin != "") {
  129. return tipoAddebitoFin;
  130. } else {
  131. sql = "SELECT " + DMFINCESrcFinancing.COLUMNNAME_FIN_FinancingTypeCharge + " FROM "
  132. + DMFINCESrcFinancing.TableName + " WHERE " + DMFINCESrcFinancing.COLUMNNAME_FINCE_SrcFinancing_ID
  133. + " in (SELECT " + DMFINCEFINANCING.COLUMNNAME_FINCE_SrcFinancing_ID + " FROM "
  134. + DMFINCEFINANCING.TableName + " WHERE " + DMFINCEFINANCING.COLUMNNAME_FINCE_FINANCING_ID + " = ?)";
  135. String tipoAddebitoSrcFin = DBUtils.getValue(trxName, sql, financingId);
  136. return tipoAddebitoSrcFin;
  137. }
  138. }
  139.  
  140.  
  141. private Integer getDocTypeId(String tipoAddebito) {
  142. String sql = "SELECT " + DMFINCEProjectFinanceParam.COLUMNNAME_C_DocType_ID + " FROM "
  143. + DMFINCEProjectFinanceParam.TableName + " WHERE "
  144. + DMFINCEProjectFinanceParam.COLUMNNAME_FIN_FinancingTypeCharge + " = ?";
  145. Integer docTypeId = DBUtils.getValueInt(trxName, sql, tipoAddebito);
  146. return docTypeId;
  147.  
  148. }
  149.  
  150.  
  151. private Integer getBPartnerFromFinancing() {
  152. String sql = "SELECT " + DMFINCEFINANCING.COLUMNNAME_C_BPartner_ID + " FROM " + DMFINCEFINANCING.TableName
  153. + " WHERE " + DMFINCEFINANCING.COLUMNNAME_FINCE_FINANCING_ID + " = ?";
  154. Integer bpartnerID = DBUtils.getValueInt(trxName, sql, financingId);
  155. return bpartnerID;
  156. }
  157.  
  158. private java.sql.Timestamp getDataIscrBil () {
  159. String sql = "SELECT " + DMFINCEFINANCING.COLUMNNAME_FIN_DateAllocBalan + " FROM " + DMFINCEFINANCING.TableName
  160. + " WHERE " + DMFINCEFINANCING.COLUMNNAME_FINCE_FINANCING_ID + " = ?";
  161. java.sql.Timestamp dataIscrBil = DBUtils.getValueTimestamp(trxName, sql, financingId);
  162. return dataIscrBil;
  163. }
  164.  
  165. //INSERIRE PIU' CONTROLLI NEI METODI
  166.  
  167. @Override
  168. public void postProcess(boolean success) {
  169.  
  170. }
  171.  
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement