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.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 Invoice Ar Back Item
- *
- * @author Deo, Jan 28, 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 = "refId", description = "ref id", type = Long.class),
- @Info(name = "refDocTypeId", description = "ref doc id", type = Long.class),
- @Info(name = "refDocNo", description = "ref doc no", type = String.class),
- @Info(name = "refDocDate", description = "ref doc date", type = String.class),
- @Info(name = "partnerId", description = "partner id", type = Long.class),
- @Info(name = "dueDate", description = "due date", type = String.class),
- @Info(name = "currCode", description = "curr code", type = String.class),
- @Info(name = "invoiceAmount", description = "invoice amount", type = Double.class),
- @Info(name = "outstandingAmount", description = "outstanding amount", type = Double.class),
- @Info(name = "handoverStatus", description = "handover status", type = String.class),
- @Info(name = "remark", description = "remark", type = String.class),
- })
- @InfoOut(value = {
- @Info(name = "id", description = "Handover Invoice Ar Back Id", type = Long.class),
- @Info(name = "tenantId", description = "tenantId", type = Long.class),
- @Info(name = "handoverInvoiceArId", description = "ou Id", type = Long.class),
- @Info(name = "refId", description = "ref Id", type = Long.class),
- @Info(name = "refDocTypeId", description = "ref Doc Type Id", type = Long.class),
- @Info(name = "refDocNo", description = "ref doc No", type = String.class),
- @Info(name = "refDocDate", description = "ref doc Date", type = String.class),
- @Info(name = "partnerId", description = "partner id", type = Long.class),
- @Info(name = "dueDate", description = "due date", type = String.class),
- @Info(name = "currCode", description = "curr code", type = String.class),
- @Info(name = "invoiceAmount", description = "invoice amount", type = Double.class),
- @Info(name = "outstandingAmount", description = "outstanding amount", type = Double.class),
- @Info(name = "remark", description = "remark", 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 ={
- CommonExceptionConstants.DATA_CANT_CHANGE_CAUSE_TENANT,
- FinanceExceptionConstantsForSasa.DOC_ALREADY_SUBMIT,
- FinanceExceptionConstantsForSasa.DOCUMENT_VERSION_NOT_UPTODATE,
- FinanceExceptionConstantsForSasa.INVOICE_AR_MUST_BE_ALREADY_HANDOVER,
- FinanceExceptionConstantsForSasa.INVOICE_AR_IS_ALREADY_OR_INPROGRESS_CREATED_IN_OTHER_DOC_HANDOVER_INVOICE_AR_BACK,
- FinanceExceptionConstantsForSasa.EMPLOYEE_ID_DOESNT_MATCH_WITH_INVOICE_AR_EMPLOYEE,
- FinanceExceptionConstantsForSasa.HANDOVER_INVOICE_AR_BACK_MUST_HAVE_AT_LEAST_ONE_ITEM,
- FinanceExceptionConstantsForSasa.HANDOVER_INVOICE_AR_ITEMS_ERROR
- })
- //@formatter:off
- public class AddHandoverInvoiceArBackItem extends DefaultBusinessTransaction implements BusinessTransaction {
- private static final Logger log = LoggerFactory.getLogger(AddHandoverInvoiceArBackItem.class);
- @Override
- public String getDescription() {
- return "Add to List Handover Invoice Ar Back Item";
- }
- @Autowired
- HandoverInvoiceArDao handoverInvoiceArDao;
- @Autowired
- HandoverInvoiceArItemDao handoverInvoiceArItemDao;
- @Autowired
- InvoiceArBalanceHandoverForSasaDao invoiceArBalanceHandoverForSasaDao;
- @Autowired
- @Qualifier("valComboValueByCode")
- private BusinessFunction valComboValueByCode;
- @Autowired
- @Qualifier("isHandoverInvoiceArItemExistsByIndex")
- private BusinessFunction isHandoverInvoiceArItemExistsByIndex;
- @Autowired
- @Qualifier("isHandoverInvoiceArByIndex")
- private BusinessFunction isHandoverInvoiceArByIndex;
- @Autowired
- @Qualifier("isHandoverInvoiceArItemByIndex")
- private BusinessFunction isHandoverInvoiceArItemByIndex;
- @Autowired
- @Qualifier("valTenantLoginCanUse")
- private BusinessFunction valTenantLoginCanUse;
- @Autowired
- @Qualifier("findHandoverInvoiceArById")
- private BusinessFunction findHandoverInvoiceArById;
- @Autowired
- @Qualifier("findHandoverInvoiceArItemById")
- private BusinessFunction findHandoverInvoiceArItemById;
- @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.valNumeric(inputDto, "refId");
- ValidationUtil.valNumeric(inputDto, "refDocTypeId");
- ValidationUtil.valBlankOrNull(inputDto, "refDocNo");
- ValidationUtil.valBlankOrNull(inputDto, "refDocDate");
- ValidationUtil.valNumeric(inputDto, "partnerId");
- ValidationUtil.valBlankOrNull(inputDto, "dueDate");
- ValidationUtil.valBlankOrNull(inputDto, "currCode");
- ValidationUtil.valNumber(inputDto, "invoiceAmount");
- ValidationUtil.valNumber(inputDto, "outstandingAmount");
- ValidationUtil.valBlankOrNull(inputDto, "handoverStatus");
- ValidationUtil.valBlankOrNull(inputDto, "remark");
- 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");
- Long refId = inputDto.getLong("refId");
- Long refDocTypeId = inputDto.getLong("refDocTypeId");
- String refDocNo = inputDto.getString("refDocNo");
- String refDocDate = inputDto.getString("refDocDate");
- Long partnerId = inputDto.getLong("partnerId");
- String dueDate = inputDto.getString("dueDate");
- String currCode = inputDto.getString("currCode");
- Double invoiceAmount = inputDto.getDouble("invoiceAmount");
- Double outstandingAmount = inputDto.getDouble("outstandingAmount");
- String handoverStatus = inputDto.getString("handoverStatus");
- String remark = inputDto.getString("remark");
- //========= 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");
- }
- //========= 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");
- }
- // 4 validasi item :
- // 1 cek ke data balance serah terima invoice findInvoiceArBalanceHandoverForSasaByIndex data nya harus ada
- // 2 validasi dapat menggunakan data invoice ar balance karna tenantId nya sama dengan tenantLoginId
- // 3 validasi invoice ar nya memang sudah dilakukan serah terima invoice ( berdasarkan ref_id dan ref_doc_type_id, cek fi_invoice_ar_balance_handover_for_sasa.flg_handover nya sudah Y )
- // 4 validasi invoice ar nya belum dan tidak sedang dilakukan serah terima invoice balik di dokumen lain (berdasarkan ref_id dan ref_doc_type_id, cek fi_invoice_ar_balance_handover_for_sasa.flg_handover_back nya masih N )
- // 5 validasi invoice ar yang akan dibuat dokumen serah terima invoice balik tidak duplikat
- // 6 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
- // 7 cek status nya harus ada di combo value handover status ( pakai BF valComboValueByCode )
- // 8 validasi berdasarkan unique index, data invoice ar nya belum ada disistem atas dokumen serah terima invoice ar balik ybs
- //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);
- //========= Validation tenantId nya sama dengan tenant login id =========
- if (!tenantLoginId.equals(invoiceArBalanceHandoverDtoResult.getLong("tenantId"))) {
- throw new CoreException(CommonExceptionConstants.DATA_CANT_CHANGE_CAUSE_TENANT, "Invoice Ar Balance Handover");
- }
- //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 IsHandoverInvoiceArItemExistsByIndex =======
- Dto uniqueIndexDto = new Dto();
- uniqueIndexDto.put("handoverInvoiceArId", handoverInvoiceArId);
- uniqueIndexDto.put("refId", refId);
- uniqueIndexDto.put("refDocTypeId", refDocTypeId);
- Dto resultUniqueIndexDto = isHandoverInvoiceArItemExistsByIndex.execute(uniqueIndexDto);
- if (resultUniqueIndexDto.getBoolean("exists")) {
- throw new CoreException(FinanceExceptionConstantsForSasa.INVOICE_AR_ALREADY_EXISTS, handoverInvoiceArId,
- refId, refDocTypeId);
- }
- //=========update flg_handover_back menjadi I (In Progress)=========
- invoiceArBalanceHandoverDtoResult.put("flgHandover", FinanceConstantsForSasa.IN_PROGRESS_TRANSACTION);
- this.prepareUpdateAudit(invoiceArBalanceHandoverDtoResult, userLoginId, datetime);
- // @Info(name = "handoverInvoiceArId", description = "Handover Invoice Ar id", type = Long.class),
- // @Info(name = "versionHeader", description = "Version Header", type = Long.class),
- // @Info(name = "refId", description = "ref id", type = Long.class),
- // @Info(name = "refDocTypeId", description = "ref doc id", type = Long.class),
- // @Info(name = "refDocNo", description = "ref doc no", type = String.class),
- // @Info(name = "refDocDate", description = "ref doc date", type = String.class),
- // @Info(name = "partnerId", description = "partner id", type = Long.class),
- // @Info(name = "dueDate", description = "due date", type = String.class),
- // @Info(name = "currCode", description = "curr code", type = String.class),
- // @Info(name = "invoiceAmount", description = "invoice amount", type = Double.class),
- // @Info(name = "outstandingAmount", description = "outstanding amount", type = Double.class),
- // @Info(name = "handoverStatus", description = "handover status", type = String.class),
- // @Info(name = "remark", description = "remark", type = String.class),
- Dto handoverInvoiceArBackItemDto = new Dto();
- handoverInvoiceArBackItemDto.put("tenantId", tenantLoginId);
- handoverInvoiceArBackItemDto.put("handoverInvoiceArId", handoverInvoiceArId);
- handoverInvoiceArBackItemDto.put("versionHeader", versionHeader);
- handoverInvoiceArBackItemDto.put("refId", refId);
- handoverInvoiceArBackItemDto.put("refDocTypeId", refDocTypeId);
- handoverInvoiceArBackItemDto.put("refDocNo", refDocNo);
- handoverInvoiceArBackItemDto.put("refDocDate", refDocDate);
- handoverInvoiceArBackItemDto.put("partnerId", partnerId);
- handoverInvoiceArBackItemDto.put("dueDate", dueDate);
- handoverInvoiceArBackItemDto.put("currCode", currCode);
- handoverInvoiceArBackItemDto.put("invoiceAmount", invoiceAmount);
- handoverInvoiceArBackItemDto.put("outstandingAmount", outstandingAmount);
- handoverInvoiceArBackItemDto.put("handoverStatus", handoverStatus);
- handoverInvoiceArBackItemDto.put("flgHandover", invoiceArBalanceHandoverDtoResult.getString("flgHandover"));
- handoverInvoiceArBackItemDto.put("remark", remark);
- this.prepareInsertAudit(handoverInvoiceArBackItemDto, userLoginId, datetime);
- this.prepareUpdateAudit(handoverInvoiceArBackItemDto, userLoginId, datetime);
- // handoverInvoiceArBackItemDto.add(invoiceArBalanceHandoverDtoResult);
- //isHandoverInvoiceArItemByIndex.execute(uniqueIndexDto);
- //update version
- handoverInvoiceArDto.put("version", versionHeader);
- this.prepareUpdateAudit(handoverInvoiceArDto, userLoginId, datetime);
- inputDto.put("handoverInvoiceArDto", handoverInvoiceArDto);
- inputDto.put("handoverInvoiceArBackItemDto", handoverInvoiceArBackItemDto);
- 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("handoverInvoiceArDto"), HandoverInvoiceAr.class);
- handoverInvoiceArDao.merge(handoverInvoiceAr.getId(), handoverInvoiceAr);
- //document = salesOrderDao.merge(docDto.getLong("id"), document);
- // add Handover InvoiceAr Item
- HandoverInvoiceArItem handoverInvoiceArItem = GsonUtil.fromDto(inputDto.getDto("handoverInvoiceArBackItemDto"), HandoverInvoiceArItem.class);
- handoverInvoiceArItemDao.merge(handoverInvoiceArItem.getId(), handoverInvoiceArItem);
- // //=========add update flg_handover_back menjadi I (In Progress)=========
- // List<Dto> invoiceArBalanceHandoverForSasaList = inputDto.getList("invoiceArBalanceHandoverForSasaList");
- // if(invoiceArBalanceHandoverForSasaList != null && invoiceArBalanceHandoverForSasaList.size() > 0){
- // for (Dto invoiceArBalanceHandoverDtoResult : invoiceArBalanceHandoverForSasaList) {
- //
- // InvoiceArBalanceHandoverForSasa invoiceArBalanceHandoverForSasa = GsonUtil.fromDto(invoiceArBalanceHandoverDtoResult, InvoiceArBalanceHandoverForSasa.class);
- // invoiceArBalanceHandoverForSasaDao.merge(invoiceArBalanceHandoverForSasa.getId(), invoiceArBalanceHandoverForSasa);
- //
- // }
- // }
- return new Dto(handoverInvoiceAr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement