Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.fin.bo.invoicearback;
- import java.util.ArrayList;
- import java.util.List;
- import org.jleaf.common.ComboIdConstants;
- import org.jleaf.common.CommonExceptionConstants;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.BusinessTransaction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.DefaultBusinessTransaction;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.core.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.erp.cb.CashBankConstants;
- import org.jleaf.erp.fin.ComboIdForSasa;
- import org.jleaf.erp.fin.FinanceConstants;
- import org.jleaf.erp.fin.FinanceConstantsForSasa;
- import org.jleaf.erp.fin.FinanceExceptionConstants;
- import org.jleaf.erp.fin.FinanceExceptionConstantsForSasa;
- import org.jleaf.erp.fin.dao.AllocationArCostDao;
- import org.jleaf.erp.fin.dao.AllocationArDao;
- import org.jleaf.erp.fin.dao.AllocationArInvoiceDao;
- import org.jleaf.erp.fin.dao.InvoiceArBalanceDao;
- import org.jleaf.erp.fin.dao.InvoiceTaxArBalanceDao;
- import org.jleaf.erp.fin.dao.ReceiptArBalanceDao;
- import org.jleaf.erp.fin.entity.AllocationAr;
- import org.jleaf.erp.fin.entity.AllocationArCost;
- import org.jleaf.erp.fin.entity.AllocationArInvoice;
- import org.jleaf.erp.fin.entity.InvoiceArBalance;
- import org.jleaf.erp.fin.entity.InvoiceTaxArBalance;
- import org.jleaf.erp.fin.entity.ReceiptArBalance;
- import org.jleaf.erp.fin.invoicearbalancehandover.FindInvoiceArBalanceHandoverForSasaByIndex;
- import org.jleaf.erp.master.MasterConstants;
- import org.jleaf.erp.master.MasterExceptionConstants;
- //import org.jleaf.erp.sls.SalesExceptionConstantsForKtmt;
- import org.jleaf.erp.fin.entity.InvoiceArBalanceHandoverForSasa;
- import org.jleaf.erp.fin.dao.InvoiceArBalanceHandoverForSasaDao;
- import org.jleaf.erp.fin.entity.HandoverInvoiceAr;
- import org.jleaf.erp.fin.entity.HandoverInvoiceArItem;
- import org.jleaf.erp.fin.dao.HandoverInvoiceArDao;
- import org.jleaf.erp.fin.dao.HandoverInvoiceArItemDao;
- import org.jleaf.util.Calc;
- import org.jleaf.util.DateUtil;
- import org.jleaf.util.DtoUtil;
- import org.jleaf.util.GsonUtil;
- import org.jleaf.util.ValidationUtil;
- import org.jleaf.validator.CommonBusinessValidator;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Service;
- /**
- * Add To ListHandover Invoice Ar Back Item
- *
- * @author Deo, Jan 17, 2020
- * @since 1.0.0
- * @version 1.0.0
- */
- //@formatter:off
- @Service
- @InfoIn(value = {
- @Info(name = "tenantLoginId", description = "Tenant Login id", type = Long.class),
- @Info(name = "userLoginId", description = "User Login id", type = Long.class),
- @Info(name = "roleLoginId", description = "Role Login id", type = Long.class),
- @Info(name = "datetime", description = "Datetime", type = String.class),
- @Info(name = "handoverInvoiceArId", description = "Handover Invoice Ar id", type = Long.class),
- @Info(name = "versionHeader", description = "Version Header", type = Long.class),
- @Info(name = "handoverInvoiceArItemList", description = "Handover Invoice Ar Item List", type = List.class)
- })
- @InfoOut(value = {
- @Info(name = "id", description = "Allocation Cash Bank In Id", type = Long.class),
- @Info(name = "tenantId", description = "tenantId", type = Long.class),
- @Info(name = "ouId", description = "ou Id", type = Long.class),
- @Info(name = "docTypeId", description = "doc Type Id", type = Long.class),
- @Info(name = "docNo", description = "doc No", type = String.class),
- @Info(name = "docDate", description = "doc Date", type = String.class),
- @Info(name = "extDocNo", description = "docDate", type = String.class),
- @Info(name = "extDocDate", description = "ext Doc No", type = String.class),
- @Info(name = "refId", description = "ref Id", type = Long.class),
- @Info(name = "refDocTypeId", description = "ref Doc Type Id", type = Long.class),
- @Info(name = "employeeId", description = "employee Id", type = Long.class),
- @Info(name = "estimateReturnDate", description = "estimate Return Date", type = String.class),
- @Info(name = "remark", description = "remark", type = String.class),
- @Info(name = "statusDoc", description = "status Doc", type = String.class),
- @Info(name = "workflowStatus", description = "workflow Status", type = String.class),
- @Info(name = "createUserId", description = "create User Id", type = Long.class),
- @Info(name = "createDateTime", description = "create Date Time", type = String.class),
- @Info(name = "updateUserId", description = "update User Id", type = String.class),
- @Info(name = "updateDateTime", description = "update Date Time", type = String.class),
- @Info(name = "version", description = "version", type = Long.class)
- })
- @ErrorList(errorKeys ={
- })
- //@formatter:off
- public class AddToListHandoverInvoiceArBackItem extends DefaultBusinessTransaction implements BusinessTransaction {
- private static final Logger log = LoggerFactory.getLogger(AddToListHandoverInvoiceArBackItem.class);
- @Override
- public String getDescription() {
- return "Add to List Handover Invoice Ar Back Item";
- }
- @Autowired
- HandoverInvoiceArDao handoverInvoiceArDao;
- @Autowired
- HandoverInvoiceArItemDao handoverInvoiceArItemDao;
- @Autowired
- @Qualifier("valComboValueByCode")
- private BusinessFunction valComboValueByCode;
- @Autowired
- @Qualifier("isHandoverInvoiceArByIndex")
- private BusinessFunction isHandoverInvoiceArByIndex;
- @Autowired
- @Qualifier("valTenantLoginCanUse")
- private BusinessFunction valTenantLoginCanUse;
- @Autowired
- @Qualifier("findHandoverInvoiceArById")
- private BusinessFunction findHandoverInvoiceArById;
- @Autowired
- @Qualifier("findInvoiceArBalanceHandoverForSasaByIndex")
- private BusinessFunction findInvoiceArBalanceHandoverForSasaByIndex;
- @SuppressWarnings("unchecked")
- @Override
- public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
- ValidationUtil.valNumeric(inputDto, "tenantLoginId");
- ValidationUtil.valNumeric(inputDto, "userLoginId");
- ValidationUtil.valNumeric(inputDto, "roleLoginId");
- ValidationUtil.valDatetime(inputDto, "datetime");
- ValidationUtil.valNumeric(inputDto, "handoverInvoiceArId");
- ValidationUtil.valNumeric(inputDto, "versionHeader");
- ValidationUtil.valDtoContainsKey(inputDto, "handoverInvoiceArItemList");
- Long tenantLoginId = inputDto.getLong("tenantLoginId");
- Long userLoginId = inputDto.getLong("userLoginId");
- Long roleLoginId = inputDto.getLong("roleLoginId");
- String datetime = inputDto.getString("datetime");
- Long handoverInvoiceArId = inputDto.getLong("handoverInvoiceArId");
- Long versionHeader = inputDto.getLong("versionHeader");
- List<Dto> handoverInvoiceArItemList = inputDto.getList("handoverInvoiceArItemList");
- //========= Validation tenant login id can be use =========
- Dto loginDto = new Dto();
- loginDto.put("tenantLoginId", tenantLoginId);
- loginDto.put("userLoginId", userLoginId);
- loginDto.put("roleLoginId", roleLoginId);
- valTenantLoginCanUse.execute(loginDto);
- Dto handoverInvoiceArDto = findHandoverInvoiceArById.execute(new Dto().put("id", handoverInvoiceArId));
- //========= Validation tenantId nya sama dengan tenant login id =========
- if (!tenantLoginId.equals(handoverInvoiceArDto.getLong("tenantId"))) {
- throw new CoreException(CommonExceptionConstants.DATA_CANT_CHANGE_CAUSE_TENANT, "Handover Invoice Ar Back Item");
- }
- //========= Validation statusDoc masih draft =========
- if(!FinanceConstantsForSasa.DRAFT_TRANSACTION.equals(handoverInvoiceArDto.get("statusDoc"))){
- throw new CoreException(FinanceExceptionConstantsForSasa.DOC_ALREADY_SUBMIT);
- }
- //========= Validation version harus uptodate =========
- if (!handoverInvoiceArDto.getLong("version").equals(versionHeader)) {
- throw new CoreException(FinanceExceptionConstantsForSasa.DOCUMENT_VERSION_NOT_UPTODATE,"Handover Invoice Ar Back Item");
- }
- List<Dto> resultHandoverInvoiceArBackItemList = new ArrayList<Dto>();
- List<Dto> failList = new ArrayList<Dto>();
- if(handoverInvoiceArItemList != null && handoverInvoiceArItemList.size() > 0){
- for(Dto HandoverInvoiceArBackItemDto : handoverInvoiceArItemList){
- try{
- ValidationUtil.valNumeric(HandoverInvoiceArBackItemDto,"refId");
- ValidationUtil.valNumeric(HandoverInvoiceArBackItemDto,"refDocTypeId");
- ValidationUtil.valNumeric(HandoverInvoiceArBackItemDto,"partnerId");
- ValidationUtil.valDate(HandoverInvoiceArBackItemDto,"dueDate");
- ValidationUtil.valDtoContainsKey(HandoverInvoiceArBackItemDto,"currCode");
- ValidationUtil.valNumber(HandoverInvoiceArBackItemDto,"invoiceAmount");
- ValidationUtil.valNumber(HandoverInvoiceArBackItemDto,"outstandingAmount");
- ValidationUtil.valDtoContainsKey(HandoverInvoiceArBackItemDto,"handoverStatus");
- ValidationUtil.valDtoContainsKey(HandoverInvoiceArBackItemDto,"remark");
- //====================yg dikembalikin error exc===============
- Long refId = Long.valueOf(HandoverInvoiceArBackItemDto.getLong("refId"));
- Long refDocTypeId = Long.valueOf(HandoverInvoiceArBackItemDto.getLong("refDocTypeId"));
- Long partnerId = Long.valueOf(HandoverInvoiceArBackItemDto.getLong("partnerId"));
- String dueDate = String.valueOf(HandoverInvoiceArBackItemDto.getString("dueDate"));
- String currCode = String.valueOf(HandoverInvoiceArBackItemDto.getString("currCode"));
- Double invoiceAmount = Double.valueOf(HandoverInvoiceArBackItemDto.getDouble("invoiceAmount"));
- Double outstandingAmount = Double.valueOf(HandoverInvoiceArBackItemDto.getDouble("outstandingAmount"));
- String handoverStatus = String.valueOf(HandoverInvoiceArBackItemDto.getString("handoverStatus"));
- String remarkItem = String.valueOf(HandoverInvoiceArBackItemDto.getString("remark"));
- //cek ke data balance serah terima invoice findInvoiceArBalanceHandoverForSasaByIndex data nya harus ada
- Dto invoiceArBalanceHandoverDto = new Dto();
- invoiceArBalanceHandoverDto.put("invoiceId", refId);
- invoiceArBalanceHandoverDto.put("docTypeId", refDocTypeId);
- Dto invoiceArBalanceHandoverDtoResult = findInvoiceArBalanceHandoverForSasaByIndex.execute(invoiceArBalanceHandoverDto);
- //validasi invoice ar nya memang sudah dilakukan serah terima invoice
- if(!GeneralConstants.YES.equals(invoiceArBalanceHandoverDtoResult.getString("flgHandover")))
- {
- throw new CoreException(FinanceExceptionConstantsForSasa.INVOICE_AR_MUST_BE_ALREADY_HANDOVER, "invoiceArBalanceHandover","invoiceId");
- }
- //validasi invoice ar nya belum dan tidak sedang dilakukan serah terima invoice balik di dokumen lain
- if(!GeneralConstants.NO.equals(invoiceArBalanceHandoverDtoResult.getString("flgHandoverBack")))
- {
- throw new CoreException(FinanceExceptionConstantsForSasa.INVOICE_AR_IS_ALREADY_OR_INPROGRESS_CREATED_IN_OTHER_DOC_HANDOVER_INVOICE_AR_BACK, "invoiceArBalanceHandover","invoiceId");
- }
- //validasi employee_id atas invoice ar yang ada di fi_invoice_ar_balance_handover_for_sasa sama dengan employee_id atas data header serah terima invoice balik
- if(!handoverInvoiceArDto.getString("employeeId").equals(invoiceArBalanceHandoverDtoResult.getString("employeeId")))
- {
- throw new CoreException(FinanceExceptionConstantsForSasa.EMPLOYEE_ID_DOESNT_MATCH_WITH_INVOICE_AR_EMPLOYEE, "employeeId");
- }
- //cek status nya harus ada di combo value handover status
- Dto comboValueHandoverStatusDto = new Dto();
- comboValueHandoverStatusDto.put("comboId", FinanceConstantsForSasa.HANDOVER_STATUS); //combo handover statu
- comboValueHandoverStatusDto.put("code", handoverStatus); //status
- comboValueHandoverStatusDto.put("varName", "Handover Status");
- valComboValueByCode.execute(comboValueHandoverStatusDto);
- //======== Validation Unique Index isHandoverInvoiceArByIndex =======
- Dto uniqueIndexDto = new Dto();
- uniqueIndexDto.put("tenantId", tenantLoginId);
- uniqueIndexDto.put("ouId", handoverInvoiceArDto.getLong("ouId"));
- uniqueIndexDto.put("docTypeId", FinanceConstantsForSasa.DOCUMENT_TYPE_HANDOVER_INVOICE_AR_BACK);
- uniqueIndexDto.put("docNo", handoverInvoiceArDto.getLong("docNo"));
- uniqueIndexDto.put("docDate", handoverInvoiceArDto.getLong("docDate"));
- isHandoverInvoiceArByIndex.execute(uniqueIndexDto);
- }
- catch (CoreException e)
- {
- log.error("add to list handover invoice ar back item error: " + e.getMessage(), e);
- HandoverInvoiceArBackItemDto.put("errorKey", e.getErrorKey());
- List<Object> argsList = new ArrayList<Object>();
- if (e.getParamValues() != null && e.getParamValues().length > 0) for (Object paramValue : e.getParamValues()) {
- argsList.add(paramValue);
- }
- HandoverInvoiceArBackItemDto.put("args", argsList);
- failList.add(HandoverInvoiceArBackItemDto);
- }
- }
- } else {
- throw new CoreException(FinanceExceptionConstantsForSasa.HANDOVER_INVOICE_AR_BACK_MUST_HAVE_AT_LEAST_ONE_ITEM);
- }
- Dto handoverInvoiceArBackItemDto = new Dto();
- handoverInvoiceArBackItemDto.put("handoverInvoiceArId", handoverInvoiceArId);
- handoverInvoiceArBackItemDto.put("tenantId", tenantLoginId);
- handoverInvoiceArBackItemDto.put("refId", GeneralConstants.NULL_REF_VALUE_LONG);
- handoverInvoiceArBackItemDto.put("refDocTypeId", GeneralConstants.NULL_REF_VALUE_LONG);
- handoverInvoiceArBackItemDto.put("partnerId", GeneralConstants.NULL_REF_VALUE_LONG);
- handoverInvoiceArBackItemDto.put("dueDate", GeneralConstants.EMPTY_VALUE);
- handoverInvoiceArBackItemDto.put("currCode", GeneralConstants.EMPTY_VALUE);
- handoverInvoiceArBackItemDto.put("invoiceAmount", GeneralConstants.NULL_REF_VALUE_LONG);
- handoverInvoiceArBackItemDto.put("outstandingAmount", GeneralConstants.NULL_REF_VALUE_LONG);
- handoverInvoiceArBackItemDto.put("handoverStatus", GeneralConstants.EMPTY_VALUE);
- handoverInvoiceArBackItemDto.put("remark", GeneralConstants.EMPTY_VALUE);
- this.prepareInsertAudit(handoverInvoiceArBackItemDto, userLoginId, datetime);
- this.prepareUpdateAudit(handoverInvoiceArBackItemDto, userLoginId, datetime);
- log.debug("resulthandoverInvoiceArBackItemDto>>>"+handoverInvoiceArBackItemDto);
- log.debug("resultHandoverInvoiceArBackItemList>>>"+resultHandoverInvoiceArBackItemList);
- inputDto.put("resultHandoverInvoiceArBackItemDto", handoverInvoiceArBackItemDto);
- inputDto.put("resultHandoverInvoiceArBackItemList", resultHandoverInvoiceArBackItemList);
- return null;
- }
- // Menambah data item serah terima invoice ar balik di table fi_handover_invoice_ar_item
- // Update data header (version nya) di table fi_handover_invoice_ar
- @SuppressWarnings({ "unchecked" })
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- // add Handover InvoiceAr
- HandoverInvoiceAr handoverInvoiceAr = GsonUtil.fromDto(inputDto.getDto("resultHandoverInvoiceArBackItemDto"), HandoverInvoiceAr.class);
- handoverInvoiceArDao.persist(handoverInvoiceAr);
- // add Handover InvoiceAr Item
- List<Dto> resultHandoverInvoiceArBackItemList = inputDto.getList("resultHandoverInvoiceArBackItemList");
- if(resultHandoverInvoiceArBackItemList != null && resultHandoverInvoiceArBackItemList.size() > 0){
- for (Dto handoverInvoiceArBackItemDto : resultHandoverInvoiceArBackItemList) {
- // add Handover InvoiceAr Item
- handoverInvoiceArBackItemDto.put("handoverInvoiceArId", handoverInvoiceAr.getId());
- HandoverInvoiceArItem handoverInvoiceArItem = GsonUtil.fromDto(handoverInvoiceArBackItemDto, HandoverInvoiceArItem.class);
- handoverInvoiceArItemDao.persist(handoverInvoiceArItem);
- }
- }
- return new Dto(handoverInvoiceAr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement