Search in sources :

Example 1 with BPartnerLocationId

use of de.metas.bpartner.BPartnerLocationId in project metasfresh-webui-api by metasfresh.

the class DefaultPackingItemCriteria method of.

public static Optional<DefaultPackingItemCriteria> of(final I_C_Order order, final ProductId productId) {
    final BPartnerLocationId bpartnerLocationId = BPartnerLocationId.ofRepoIdOrNull(order.getC_BPartner_ID(), order.getC_BPartner_Location_ID());
    final PricingSystemId pricingSystemId = PricingSystemId.ofRepoIdOrNull(order.getM_PricingSystem_ID());
    final ZonedDateTime date = TimeUtil.asZonedDateTime(order.getDatePromised());
    final SOTrx soTrx = SOTrx.ofBoolean(order.isSOTrx());
    final boolean anyNull = Stream.of(bpartnerLocationId, pricingSystemId, date, productId).anyMatch(Objects::isNull);
    if (anyNull) {
        return Optional.empty();
    }
    return Optional.of(builder().bPartnerLocationId(bpartnerLocationId).productId(productId).pricingSystemId(pricingSystemId).date(date).soTrx(soTrx).build());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) BPartnerLocationId(de.metas.bpartner.BPartnerLocationId) SOTrx(de.metas.lang.SOTrx) Objects(java.util.Objects) PricingSystemId(de.metas.pricing.PricingSystemId)

Example 2 with BPartnerLocationId

use of de.metas.bpartner.BPartnerLocationId in project metasfresh-webui-api by metasfresh.

the class DefaultPackingItemCriteria method of.

public static Optional<DefaultPackingItemCriteria> of(@NonNull final I_C_Invoice invoice, @NonNull final ProductId productId) {
    final BPartnerLocationId bpartnerLocationId = BPartnerLocationId.ofRepoIdOrNull(invoice.getC_BPartner_ID(), invoice.getC_BPartner_Location_ID());
    final PriceListId priceListId = PriceListId.ofRepoIdOrNull(invoice.getM_PriceList_ID());
    final ZonedDateTime date = TimeUtil.asZonedDateTime(invoice.getDateInvoiced());
    final boolean anyNull = Stream.of(bpartnerLocationId, priceListId, date, productId).anyMatch(Objects::isNull);
    if (anyNull) {
        return Optional.empty();
    }
    return Optional.of(builder().productId(productId).priceListId(priceListId).date(date).bPartnerLocationId(bpartnerLocationId).build());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) PriceListId(de.metas.pricing.PriceListId) BPartnerLocationId(de.metas.bpartner.BPartnerLocationId) Objects(java.util.Objects)

Example 3 with BPartnerLocationId

use of de.metas.bpartner.BPartnerLocationId in project metasfresh-webui-api by metasfresh.

the class LetterRestController method createNewLetter.

@PostMapping
@ApiOperation("Creates a new letter")
public JSONLetter createNewLetter(@RequestBody final JSONLetterRequest request) {
    userSession.assertLoggedIn();
    final DocumentPath contextDocumentPath = JSONDocumentPath.toDocumentPathOrNull(request.getDocumentPath());
    // 
    // Extract context BPartner, Location and Contact
    final BoilerPlateContext context = documentCollection.createBoilerPlateContext(contextDocumentPath);
    final BPartnerId bpartnerId = BPartnerId.ofRepoIdOrNull(context.getC_BPartner_ID(-1));
    final BPartnerLocationId bpartnerLocationId = BPartnerLocationId.ofRepoIdOrNull(bpartnerId, context.getC_BPartner_Location_ID(-1));
    final UserId contactId = UserId.ofRepoIdOrNull(context.getAD_User_ID(-1));
    // 
    // Build BPartnerAddress
    final PlainDocumentLocation documentLocation = PlainDocumentLocation.builder().bpartnerId(bpartnerId).bpartnerLocationId(bpartnerLocationId).contactId(contactId).build();
    Services.get(IDocumentLocationBL.class).setBPartnerAddress(documentLocation);
    final String bpartnerAddress = documentLocation.getBPartnerAddress();
    final WebuiLetter letter = lettersRepo.createNewLetter(WebuiLetter.builder().contextDocumentPath(contextDocumentPath).ownerUserId(userSession.getLoggedUserId()).adOrgId(context.getAD_Org_ID(userSession.getOrgId().getRepoId())).bpartnerId(BPartnerId.toRepoId(bpartnerId)).bpartnerLocationId(BPartnerLocationId.toRepoId(bpartnerLocationId)).bpartnerContactId(UserId.toRepoId(contactId)).bpartnerAddress(bpartnerAddress));
    return JSONLetter.of(letter);
}
Also used : UserId(de.metas.user.UserId) BPartnerLocationId(de.metas.bpartner.BPartnerLocationId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) BPartnerId(de.metas.bpartner.BPartnerId) PlainDocumentLocation(de.metas.document.model.impl.PlainDocumentLocation) IDocumentLocationBL(de.metas.document.IDocumentLocationBL) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

BPartnerLocationId (de.metas.bpartner.BPartnerLocationId)3 ZonedDateTime (java.time.ZonedDateTime)2 Objects (java.util.Objects)2 BPartnerId (de.metas.bpartner.BPartnerId)1 IDocumentLocationBL (de.metas.document.IDocumentLocationBL)1 PlainDocumentLocation (de.metas.document.model.impl.PlainDocumentLocation)1 SOTrx (de.metas.lang.SOTrx)1 BoilerPlateContext (de.metas.letters.model.MADBoilerPlate.BoilerPlateContext)1 PriceListId (de.metas.pricing.PriceListId)1 PricingSystemId (de.metas.pricing.PricingSystemId)1 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)1 UserId (de.metas.user.UserId)1 ApiOperation (io.swagger.annotations.ApiOperation)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1