Skip to Content
0
Former Member
Jul 04, 2011 at 01:39 PM

Correction Invoice and "invalid document structure" problem

179 Views

Hello!

Can anybody explain what properties are obligatory for correction invoices? I'm trying to add() one and it always say -5002: invalid document structure.

In the CSI1 table I see linenum has to be unique, every baseline is twice. Do I make any stupid mistake? If so - where? What's wrong? Something is ommitted?...

Thanks in advance!

This is a snippet (two loops are unnecessary, I was looking for other ways). I'm trying just to zero the invoice. Should quantity in was lines be negative? It does not matter - everytime -5002...

	@Test
	public void testSAPCorrectionInvoice() throws SBOCOMException {
		ICompany company = sapConnector.getCompany();

		// Integer srcDocEntry = 6457;
		Integer srcDocEntry = 7084;// this one has no batches
		logger.debug("Creating correction to: " + srcDocEntry);

		// source doc
		IDocuments srcDoc = SBOCOMUtil.getDocuments(company,
				SBOCOMConstants.BoObjectTypes_Document_oInvoices, srcDocEntry);

		logger.debug("srcDoc: " + srcDoc.getDocObjectCode() + ", "
				+ srcDoc.getDocNum());

		IDocuments sapDoc = SBOCOMUtil.newDocuments(company,
				SBOCOMConstants.BoObjectTypes_Document_oCorrectionInvoice);
		// header:
		sapDoc.setHandWritten(SBOCOMConstants.BoYesNoEnum_tNO);
		sapDoc.setSeries(317);
		sapDoc.setDocType(SBOCOMConstants.BoDocumentTypes_dDocument_Items);

		sapDoc.setCardCode(srcDoc.getCardCode());
		sapDoc.setCardName(srcDoc.getCardName());
		sapDoc.setAddress(srcDoc.getAddress());
		String federalTaxID = srcDoc.getFederalTaxID();
		if (federalTaxID.length() > 0)
			sapDoc.setFederalTaxID(federalTaxID);

		sapDoc.setDocDate(new Date());
		sapDoc.setDocDueDate(new Date());
		sapDoc.setSalesPersonCode(srcDoc.getSalesPersonCode());
		sapDoc.setDocCurrency(srcDoc.getDocCurrency());
		sapDoc.setPaymentGroupCode(srcDoc.getPaymentGroupCode());
		sapDoc.setTransportationCode(srcDoc.getTransportationCode());
		sapDoc.setContactPersonCode(srcDoc.getContactPersonCode());
		// sapDoc.setDiscountPercent(0.0);
		sapDoc.setComments("zwrot towaru");
		// sapDoc.setDocTotal(0.0);
		sapDoc.setVatDate(srcDoc.getVatDate());

		// items
		IDocument_Lines lines = sapDoc.getLines();

		int lineno = 0;
		IDocument_Lines srcLines = srcDoc.getLines();
		for (int i = 0; i < srcLines.getCount(); i++) {
			srcLines.setCurrentLine(i);
			logger.debug("line " + i + ", item: " + srcLines.getItemCode());
			if (lineno > 0)
				lines.add();
			lines.setCurrentLine(lineno++);

			lines.setItemCode(srcLines.getItemCode());
			lines.setItemDescription(srcLines.getItemDescription());
			lines.setWarehouseCode(srcLines.getWarehouseCode());
			lines.setPrice(srcLines.getPrice());
			lines.setDiscountPercent(srcLines.getDiscountPercent());
			lines.setTaxCode(srcLines.getTaxCode());
			lines.setBaseEntry(srcDocEntry);
			lines.setBaseType(srcDoc.getDocObjectCode());
			lines.setBaseLine(i);
			lines.setVatGroup(srcLines.getVatGroup());
			lines
					.setCorrectionInvoiceItem(SBOCOMConstants.BoCorInvItemStatus_ciis_Was);

			double quantity_was = srcLines.getQuantity();
			lines.setQuantity(quantity_was);
		}

		for (int i = 0; i < srcLines.getCount(); i++) {
			srcLines.setCurrentLine(i);
			logger.debug("line " + i + ", item: " + srcLines.getItemCode());
			if (lineno > 0)
				lines.add();
			lines.setCurrentLine(lineno++);
			double quantity_diff = 0;

			lines.setItemCode(srcLines.getItemCode());
			lines.setWarehouseCode(srcLines.getWarehouseCode());
			lines.setPrice(srcLines.getPrice());
			lines.setDiscountPercent(srcLines.getDiscountPercent());
			lines.setTaxCode(srcLines.getTaxCode());
			lines.setBaseEntry(srcDocEntry);
			lines.setBaseType(srcDoc.getDocObjectCode());
			lines.setBaseLine(i);
			lines.setVatGroup(srcLines.getVatGroup());
			lines
					.setCorrectionInvoiceItem(SBOCOMConstants.BoCorInvItemStatus_ciis_ShouldBe);

			double quantity_was = srcLines.getQuantity();

			double quantity_is = 0; //quantity_was - quantity_diff;
			lines.setQuantity(quantity_is);

		}

		int result = sapDoc.add();
		String info = company.getLastErrorDescription();

		logger.debug("res = " + result + ", info: " + info);

		if (result != 0)
			throw new EBladKorektyNrPartii(
					"Cannot create document: " + info);

	}

Edited by: WodzGalopujacySkleroz on Jul 4, 2011 5:03 PM