Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.fin.bo.invoicear;
- 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.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.erp.fin.FinanceConstantsForSasa;
- import org.jleaf.erp.fin.FinanceExceptionConstantsForSasa;
- 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;
- /**
- * Edit Handover Invoice Ar Back Item
- *
- * @author Deo, Jan 23, 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 = "id", description = "id", type = Long.class),
- @Info(name = "remark", description = "remark", type = String.class),
- @Info(name = "version", description = "version", type = Long.class),
- @Info(name = "handoverStatus", description = "handover status", type = String.class),
- @Info(name = "handoverInvoiceArId", description = "handover invoice ar id", type = Long.class)
- })
- @InfoOut(value = {
- @Info(name = "id", description = "id", type = Long.class),
- @Info(name = "handoverInvoiceArId", description = "Handover Invoice Ar Id", type = Long.class),
- })
- @ErrorList(errorKeys ={
- CommonExceptionConstants.DATA_CANT_CHANGE_CAUSE_TENANT,
- FinanceExceptionConstantsForSasa.DOC_ALREADY_SUBMIT,
- FinanceExceptionConstantsForSasa.DOCUMENT_VERSION_NOT_UPTODATE
- })
- //@formatter:off
- public class EditHandoverInvoiceArBackItem extends DefaultBusinessTransaction implements BusinessTransaction {
- private static final Logger log = LoggerFactory.getLogger(EditHandoverInvoiceArBack.class);
- @Override
- public String getDescription() {
- return "Edit Handover Invoice Ar Back Item";
- }
- @Autowired
- HandoverInvoiceArItemDao handoverInvoiceArItemDao;
- @Autowired
- HandoverInvoiceArDao handoverInvoiceArDao;
- @Autowired
- @Qualifier("valTenantLoginCanUse")
- private BusinessFunction valTenantLoginCanUse;
- @Autowired
- @Qualifier("valComboValueByCode")
- private BusinessFunction valComboValueByCode;
- @Autowired
- @Qualifier("findHandoverInvoiceArById")
- private BusinessFunction findHandoverInvoiceArById;
- @Autowired
- @Qualifier("findHandoverInvoiceArItemByIndex")
- private BusinessFunction findHandoverInvoiceArItemByIndex;
- @Autowired
- @Qualifier("getHandoverInvoiceArBackItemListByHandoverInvoiceArId")
- private BusinessFunction getHandoverInvoiceArBackItemListByHandoverInvoiceArId;
- @Autowired
- @Qualifier("findHandoverInvoiceArItemById")
- private BusinessFunction findHandoverInvoiceArItemById;
- @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, "id");
- ValidationUtil.valDtoContainsKey(inputDto, "remark");
- ValidationUtil.valNumeric(inputDto, "version");
- ValidationUtil.valBlankOrNull(inputDto, "handoverStatus");
- ValidationUtil.valNumeric(inputDto, "handoverInvoiceArId");
- Long tenantLoginId = inputDto.getLong("tenantLoginId");
- Long userLoginId = inputDto.getLong("userLoginId");
- Long roleLoginId = inputDto.getLong("roleLoginId");
- String datetime = inputDto.getString("datetime");
- Long id = inputDto.getLong("id");
- String remark = inputDto.getString("remark");
- Long version = inputDto.getLong("version");
- String handoverStatus = inputDto.getString("handoverStatus");
- Long handoverInvoiceArId = inputDto.getLong("handoverInvoiceArId");
- //========= Validation tenant login nya bukan superadmin =========
- Dto loginDto = new Dto();
- loginDto.put("tenantLoginId", tenantLoginId);
- loginDto.put("userLoginId", userLoginId);
- loginDto.put("roleLoginId", roleLoginId);
- valTenantLoginCanUse.execute(loginDto);
- //get data header
- Dto handoverInvoiceArDto = findHandoverInvoiceArById.execute(new Dto().put("id", id));
- //========= 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(version)) {
- throw new CoreException(FinanceExceptionConstantsForSasa.DOCUMENT_VERSION_NOT_UPTODATE,"Handover Invoice Ar Back");
- }
- //=========== get data item ==============
- Dto handoverInvoiceArItemDto = findHandoverInvoiceArItemById.execute(new Dto().put("id", id));
- //validasi tenant login id dengan tenant id
- if (!tenantLoginId.equals(handoverInvoiceArItemDto.getLong("tenantId"))) {
- throw new CoreException(CommonExceptionConstants.DATA_CANT_USE_DIFF_TENANT, "Handover Invoice AR Back Item", "Invoice Ar Handover Item");
- }
- if (!handoverInvoiceArItemDto.getLong("version").equals(version)) {
- throw new CoreException(FinanceExceptionConstantsForSasa.DOCUMENT_VERSION_NOT_UPTODATE,"Handover Invoice Ar Back Item");
- }
- //cek status nya harus ada di combo value handover status
- Dto comboValueHandoverStatusDto = new Dto();
- comboValueHandoverStatusDto.put("comboId", FinanceConstantsForSasa.HANDOVER_STATUS);
- comboValueHandoverStatusDto.put("code", handoverInvoiceArItemDto.getString("handoverStatus"));
- comboValueHandoverStatusDto.put("varName", "Handover Status");
- valComboValueByCode.execute(comboValueHandoverStatusDto);
- inputDto.put("handoverInvoiceArItemDto", handoverInvoiceArItemDto);
- inputDto.put("handoverInvoiceArDto", handoverInvoiceArDto);
- this.prepareUpdateAudit(handoverInvoiceArItemDto, userLoginId, datetime);
- handoverInvoiceArItemDto.put("status", handoverStatus);
- handoverInvoiceArItemDto.put("remark", remark);
- handoverInvoiceArItemDto.put("version", version);
- this.prepareUpdateAudit(handoverInvoiceArDto, userLoginId, datetime);
- handoverInvoiceArDto.put("version", version);
- inputDto.put("handoverInvoiceArDto", handoverInvoiceArDto);
- inputDto.put("handoverInvoiceArItemDto", handoverInvoiceArItemDto);
- return null;
- }
- @Override
- public Dto process(Dto inputDto, Dto originalDto) throws Exception {
- Dto handoverInvoiceArDto = inputDto.getDto("handoverInvoiceArDto");
- // Update data header
- HandoverInvoiceAr handoverInvoiceAr = GsonUtil.fromDto(handoverInvoiceArDto, HandoverInvoiceAr.class);
- handoverInvoiceAr = handoverInvoiceArDao.merge(handoverInvoiceArDto.getLong("id"), handoverInvoiceAr);
- Dto handoverInvoiceArItemDto = inputDto.getDto("handoverInvoiceArItemDto");
- // Update data item
- HandoverInvoiceArItem handoverInvoiceArItem = GsonUtil.fromDto(handoverInvoiceArItemDto, HandoverInvoiceArItem.class);
- handoverInvoiceArItem = handoverInvoiceArItemDao.merge(handoverInvoiceArItemDto.getLong("id"), handoverInvoiceArItem);
- return new Dto().put("handoverInvoiceArId", handoverInvoiceAr.getId());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement