Created
February 5, 2025 14:51
-
-
Save cesarockstar1985/2cff2ca0eb1b442f35671090b1bab783 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //COMANDO DE VENTAS CAST_SI2 | |
| import java.sql.Connection; | |
| import java.sql.PreparedStatement; | |
| import java.sql.ResultSet; | |
| import java.sql.Timestamp; | |
| import java.text.SimpleDateFormat; | |
| import java.util.List; | |
| import javax.sql.DataSource; | |
| import cast.portal.audit.ent.Audit; | |
| import cast.portal.document.ent.DocumentQueue; | |
| import cast.portal.invoice.ent.Invoice | |
| import cast.portal.invoice.ent.InvoiceDetail; | |
| import cast.portal.security.ent.Group; | |
| import cast.portal.security.ent.User; | |
| import cast.portal.util.DataBaseHelper; | |
| import cast.portal.route.ent.Event; | |
| import cast.portal.document.srv.DocumentService; | |
| import cast.portal.config.srv.ConfigurationService; | |
| import org.codehaus.groovy.grails.web.context.ServletContextHolder; | |
| import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes; | |
| import org.springframework.context.ApplicationContext; | |
| import org.springframework.jdbc.datasource.DataSourceUtils; | |
| String smsText = commandData.get("sms.text") | |
| long documentTime= Long.valueOf(commandData.get("documentTime")) | |
| Timestamp dtTimeStamp = new Timestamp(documentTime) //HORA DEL DOCUMENTO | |
| String message = null | |
| PreparedStatement ps | |
| PreparedStatement psInvoice | |
| ResultSet rs | |
| Connection connPortal | |
| DataSource dataSource | |
| ConfigurationService configurationService; | |
| DocumentService documentService; | |
| String subjectCode = "" | |
| String subjectName = "" | |
| double saleAmount = 0 | |
| try { | |
| ApplicationContext applicationContext = ServletContextHolder.getServletContext().getAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT) | |
| configurationService = applicationContext.getBean('configurationService') | |
| documentService = applicationContext.getBean('documentService') | |
| dataSource = applicationContext.getBean('dataSource') | |
| connPortal = DataSourceUtils.getConnection(dataSource) | |
| connPortal.setAutoCommit(false) | |
| String adjustWarehouse = configurationService.getConfiguration("adjust.warehouse").trim() | |
| List wareHouseList = [] | |
| if(adjustWarehouse.equals("true")){ | |
| log.debug("UTILIZA STOCK: "+adjustWarehouse) | |
| wareHouseList = documentService.getWareHouseId(user, connPortal, rs, ps) | |
| } | |
| HashMap invoiceMap = getInvoiceMap(smsText) | |
| HashMap headerMap = invoiceMap.get("header") | |
| List detailsList = invoiceMap.get("details") | |
| log.debug("headerMap: "+headerMap) | |
| log.debug("detailsList: "+detailsList) | |
| // Ensure subjectName is set correctly | |
| if (headerMap.containsKey("subjectName")) { | |
| subjectName = headerMap.get("subjectName") | |
| } else { | |
| log.error("Subject name is missing in the header map") | |
| throw new IllegalArgumentException("Subject name cannot be null") | |
| } | |
| long eventId = documentService.markVisit(user.username, headerMap.get("subjectCode"), documentTime, headerMap.get("netTotal"), "VD") | |
| log.debug("eventId: "+eventId) | |
| long invoiceId = insertInvoiceHeader(user, headerMap, wareHouseList, dtTimeStamp, eventId, connPortal, ps, rs) | |
| log.debug("invoiceId: "+invoiceId) | |
| documentService.updateData("invoice_amount", headerMap.get('netTotal'), eventId, connPortal, psInvoice) | |
| //Desde Aca | |
| /** | |
| * Se crea el String para auditar el Invoice | |
| * invoiceInstance.salesmanUsername = userInstance.username | |
| ***/ | |
| Group groupInstance = user.getMainGroup() | |
| Date documentDate = new Date(dtTimeStamp.getTime()) | |
| headerMap.put("id",invoiceId) | |
| headerMap.put("creationDate",documentDate) | |
| headerMap.put("deliveryDate",documentDate) | |
| if(wareHouseList.size() > 0){ | |
| log.info("deposito del portal"); | |
| headerMap.put("warehouseCode",wareHouseList.get(1)) | |
| headerMap.put("warehouseName",wareHouseList.get(2)) | |
| } | |
| headerMap.put("event", Event.get(eventId)) | |
| headerMap.put("group", groupInstance) | |
| headerMap.put("companyAlias", groupInstance.name) | |
| headerMap.put("user", user) | |
| headerMap.put("salesmanUsername", user.username) | |
| headerMap.put("customerVat", true) | |
| headerMap.put("status", "N") | |
| Invoice invoiceInstance = new Invoice(headerMap) | |
| String invoiceAuditString = documentService.getChangedText(invoiceInstance, Audit.CREATE)+"€" | |
| invoiceInstance.discard() | |
| //Hasta Aca | |
| documentService.addToDocumentQueue(invoiceId, headerMap.get("number"), DocumentQueue.INVOICE , dtTimeStamp, headerMap.get("subjectCode"), headerMap.get("subjectName"), headerMap.get("subjectFiscalNumber"), user, headerMap.get("typeName"),headerMap.get("netTotal")) | |
| long movementId = 0 | |
| if(wareHouseList.size()>0){ | |
| movementId = documentService.insertMovement(headerMap.get("number"), headerMap.get("observation"), user.id, wareHouseList.get(0), connPortal, ps, rs,dtTimeStamp) | |
| log.debug("MovementId: "+movementId) | |
| } | |
| double productQuantity = 0 | |
| double bonusQuantity = 0 | |
| double totalQuantity = 0 | |
| HashMap invoiceDetailMap | |
| int rowNumber = 0 | |
| InvoiceDetail invoiceDetailInstance | |
| long invoiceDetailId = 0 | |
| invoiceInstance = Invoice.get(invoiceId) | |
| for(int i = 0; i < detailsList.size(); i++){ | |
| invoiceDetailMap = detailsList.get(i) | |
| rowNumber = i + 1 | |
| productQuantity = 0 | |
| bonusQuantity = invoiceDetailMap.get("bonusQuantity") | |
| totalQuantity = invoiceDetailMap.get("totalQuantity") | |
| if(totalQuantity > 0){ | |
| productQuantity = invoiceDetailMap.get("productQuantity") | |
| }else{ | |
| productQuantity = invoiceDetailMap.get("productQuantity") - bonusQuantity | |
| } | |
| invoiceDetailId = insertInvoiceDetail(invoiceDetailMap, productQuantity, bonusQuantity, rowNumber, invoiceId, connPortal, ps, rs) | |
| if(movementId != 0){ | |
| documentService.insertMovementDetail(invoiceDetailMap.get("productCode"), productQuantity+bonusQuantity , invoiceDetailMap.get("unitPrice"), wareHouseList.get(0), movementId, connPortal, ps, rs) | |
| } | |
| //Desde Aca | |
| /* | |
| * Empieza a crear el String para la auditoria del detalle | |
| * */ | |
| invoiceDetailMap.put("id", invoiceDetailId) | |
| invoiceDetailMap.put("invoice", invoiceInstance) | |
| invoiceDetailMap.put("rowNumber", rowNumber) | |
| invoiceDetailMap.put("quantity", productQuantity) | |
| invoiceDetailMap.put("bonusQuantity", bonusQuantity) | |
| invoiceDetailInstance = new InvoiceDetail(invoiceDetailMap) | |
| invoiceAuditString += documentService.getChangedText(invoiceDetailInstance, Audit.CREATE) | |
| //invoiceAuditString += getInvoiceDetailAuditString(invoiceDetailMap, productQuantity, bonusQuantity, rowNumber, invoiceId, invoiceDetailId, invoiceDetailInstance) // getChangedText(invoiceDetailInstance, Audit.CREATE) | |
| invoiceDetailInstance.discard() | |
| if(i < detailsList.size()-1){ | |
| invoiceAuditString += "ŧ" | |
| } | |
| //Hasta Aca | |
| } | |
| log.info("antes de la auditoria"); | |
| //documentService.addToAudit("Invoice", invoiceId, Audit.CREATE, user, invoiceAuditString) | |
| documentService.addToAudit(connPortal, "Invoice", invoiceId, Audit.CREATE, user, invoiceAuditString.toString()) | |
| log.info("despues de la auditoria"); | |
| String fiscalStampNumber = headerMap.get("fiscalStampNumber") | |
| String factura = headerMap.get("number") | |
| String boca = "", sucursal = "" | |
| //sucursal = factura.substring(0,3) | |
| //boca = factura.substring(4,7) | |
| String [] splitFactura = factura.split("-"); | |
| sucursal = splitFactura[0]; | |
| boca = splitFactura[1]; | |
| log.info("boca: "+boca+", sucursal: "+sucursal) | |
| if(!fiscalStampNumber.equals("")){ | |
| long book = updateBook(connPortal, ps, user, fiscalStampNumber, dtTimeStamp, boca, sucursal) | |
| log.info("UPDATE book set last_value = last_value + 1, last_value_date = '$dtTimeStamp' where fiscal_stamp_number = '"+fiscalStampNumber+"' and branch_office = '"+sucursal+"' and sale_point = '"+boca+"'") | |
| } | |
| subjectCode = headerMap.get("subjectCode") | |
| subjectName = headerMap.get("subjectName") | |
| saleAmount = headerMap.get("netTotal") | |
| message = "0| Venta procesada correctamente, Cliente: "+subjectCode+" - "+subjectName+" Total Venta: "+saleAmount | |
| log.info(message); | |
| /*if(message != null){ | |
| try{ | |
| documentService.sendMailProspectCreated(subjectCode, saleAmount, DocumentQueue.INVOICE, connPortal) | |
| log.info("envio correctamente el correo"); | |
| connPortal.commit() | |
| } catch (Throwable e) { | |
| log.error("Error en sendMailProspectCreated: "+ e,e); | |
| throw e | |
| } | |
| }*/ | |
| /* YA SE MANDA CORREO EN EL COMANDO DE ALTA CAST_SPP*/ | |
| /*if(message != null){ | |
| log.info("antes de mandar correo") | |
| documentService.sendMailProspectCreated(subjectCode, saleAmount, DocumentQueue.INVOICE, connPortal) | |
| log.info("envio correctamente el correo"); | |
| }*/ | |
| connPortal.commit() | |
| log.info("ya commiteo"); | |
| } catch (Throwable e) { | |
| log.error("ERROR EN EL COMMANDO: "+e.getMessage()); | |
| log.error("ERROR EN EL COMMANDO: "+e.getMessage(), e); | |
| connPortal.rollback(); | |
| log.error("rollback general"); | |
| throw e | |
| }finally{ | |
| DataBaseHelper.closeRs(rs); | |
| DataBaseHelper.closePs(psInvoice); | |
| DataBaseHelper.closePs(ps); | |
| DataSourceUtils.releaseConnection(connPortal, dataSource); | |
| } | |
| return message | |
| private HashMap getInvoiceMap(String smsText) { | |
| Map invoiceMapToReturn = [: ] | |
| String[] messageBlocks = smsText.split("¥") //Parseo del Mensaje por Bloques "¥" | |
| String[] detailProducts = messageBlocks[1].split("€") | |
| String[] paymentMethods = messageBlocks[2].split("\$") | |
| int detailRows = detailProducts.length - 1 | |
| // int detailRows = messageBlocks.length - 1 | |
| Map headerMap = [: ] | |
| List detailsList = [] | |
| List paymentList = [] | |
| String[] headerFields = messageBlocks[0].split("¤") | |
| for (int i = 1; i < headerFields.length; i++) { | |
| switch (i) { | |
| case 1: | |
| headerMap.put("subjectCode", headerFields[i]) | |
| break | |
| case 2: | |
| headerMap.put("subjectName", headerFields[i]) | |
| break | |
| case 3: | |
| headerMap.put("subjectFiscalNumber", headerFields[i]) | |
| break | |
| case 4: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("subjectCompanyAlias", headerFields[i]) | |
| } else { | |
| headerMap.put("subjectCompanyAlias", "") | |
| } | |
| break | |
| case 5: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("subjectContactName", headerFields[i]) | |
| } else { | |
| headerMap.put("subjectContactName", "") | |
| } | |
| break | |
| case 6: | |
| if (!headerFields[i].equals("-1")) { | |
| //1.Cliente 2.Prospecto | |
| if (headerFields[i].split("\\.").size() > 1) { | |
| headerMap.put("subjectType", headerFields[i].split("\\.")[1]) | |
| } else { | |
| headerMap.put("subjectType", headerFields[i]) | |
| } | |
| } else { | |
| headerMap.put("subjectType", "Cliente") | |
| } | |
| break | |
| case 7: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("subjectAddress", headerFields[i]) | |
| } else { | |
| headerMap.put("subjectAddress", "") | |
| } | |
| break | |
| case 8: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("subjectPhone", headerFields[i]) | |
| } else { | |
| headerMap.put("subjectPhone", "") | |
| } | |
| break | |
| case 9: | |
| //Subject Status | |
| // if(!headerFields[i].equals("-1")){ | |
| //1.Activo 2.Inactivo | |
| // headerMap.put("subjectStatus", headerFields[i].split("\\.")[1]) | |
| //}else{ | |
| // headerMap.put("subjectStatus", "Activo") | |
| //} | |
| break | |
| case 10: | |
| //Credit Line | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("subjectCreditLine", headerFields[i]) | |
| } else { | |
| headerMap.put("subjectCreditLine", "") | |
| } | |
| break | |
| case 11: | |
| //delinquency | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("subjectDelinquency", headerFields[i]) | |
| } else { | |
| headerMap.put("subjectDelinquency", "") | |
| } | |
| break | |
| case 12: | |
| //fiscalStampNumber: timbrado | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("fiscalStampNumber", headerFields[i]) | |
| } else { | |
| headerMap.put("fiscalStampNumber", "") | |
| } | |
| break | |
| case 13: | |
| // subjectValidity invoicing.validez = it | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("validity", headerFields[i]) | |
| } else { | |
| headerMap.put("validity", "") | |
| } | |
| break | |
| case 14: | |
| headerMap.put("number", headerFields[i]) | |
| break | |
| case 15: | |
| //invoicing.invoiceDate = it | |
| headerMap.put("invoiceDate", headerFields[i]) | |
| break | |
| case 16: | |
| // seleccionar lista de precios | |
| if (!headerFields[i].equals("-1")) { | |
| //1.Lista 1 2.Lista 2 | |
| if (headerFields[i].split("\\.").size() > 1) { | |
| headerMap.put("priceListCode", headerFields[i].split("\\.")[0]) | |
| headerMap.put("priceListName", headerFields[i].split("\\.")[1]) | |
| } else { | |
| headerMap.put("priceListCode", headerFields[i]) | |
| headerMap.put("priceListName", headerFields[i]) | |
| } | |
| } else { | |
| headerMap.put("priceListCode", "") | |
| headerMap.put("priceListName", "") | |
| } | |
| break | |
| case 17: | |
| if (!headerFields[i].equals("-1")) { | |
| //1.Contado, 2.Crédito | |
| String[] typeSplit = headerFields[i].split("\\.") | |
| headerMap.put("type", typeSplit[0]) | |
| headerMap.put("typeName", typeSplit[1]) | |
| } else { | |
| headerMap.put("type", "") | |
| headerMap.put("typeName", "") | |
| } | |
| break | |
| case 18: | |
| if (!headerFields[i].equals("-1")) { | |
| //1.Efectivo 2.Cheque | |
| if (headerFields[i].split("\\.").size() > 1) { | |
| headerMap.put("conditionCode", headerFields[i].split("\\.")[0]) | |
| headerMap.put("conditionName", headerFields[i].split("\\.")[1]) | |
| } else { | |
| headerMap.put("conditionCode", headerFields[i]) | |
| headerMap.put("conditionName", headerFields[i]) | |
| } | |
| } else { | |
| headerMap.put("conditionCode", "") | |
| headerMap.put("conditionName", "") | |
| } | |
| break | |
| case 19: | |
| // sale_condition | |
| break | |
| case 20: | |
| // cambio moneda | |
| if (!headerFields[i].equals("-1")) { | |
| //1.Guaranies 2.Dolares | |
| if (headerFields[i].split("\\.").size() > 1) { | |
| headerMap.put("currencyCode", headerFields[i].split("\\.")[0]) | |
| headerMap.put("currencyName", headerFields[i].split("\\.")[1]) | |
| } else { | |
| headerMap.put("currencyCode", headerFields[i]) | |
| headerMap.put("currencyName", headerFields[i]) | |
| } | |
| } else { | |
| headerMap.put("currencyCode", "") | |
| headerMap.put("currencyName", "") | |
| } | |
| break | |
| case 21: | |
| // Cambio Moneda | |
| log.info("###########################################CURRENCY " + headerFields[i] + "##################################################") | |
| if (!headerFields[i].equals("-1")) { | |
| try { | |
| double currencyExchange = Double.parseDouble(headerFields[i]) | |
| headerMap.put("currencyExchange", currencyExchange) | |
| log.info("Currency exchange value: " + currencyExchange) | |
| } catch (NumberFormatException e) { | |
| log.error("Invalid currency exchange value: " + headerFields[i], e) | |
| headerMap.put("currencyExchange", 0) | |
| } | |
| } else { | |
| log.info("Currency exchange value is -1, setting to 0") | |
| headerMap.put("currencyExchange", 0) | |
| } | |
| break | |
| case 22: | |
| //Codigo Producto | |
| break | |
| case 23: | |
| //Descuento Maximo | |
| break | |
| case 24: | |
| //PORCENTAJE DE DESCUENTO | |
| //Descuento | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("discountRate", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("discountRate", 0) | |
| } | |
| break | |
| case 25: | |
| //CANTIDAD BONIFICADA | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("bonusQuantity", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("bonusQuantity", 0) | |
| } | |
| break | |
| case 26: | |
| //TOTAL IVA 5 % | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("vat05Total", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("vat05Total", 0) | |
| } | |
| break | |
| case 27: | |
| //TOTAL IVA 10 % | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("vat10Total", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("vat10Total", 0) | |
| } | |
| break | |
| case 28: | |
| //Total Venta 5 % | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("vatted05Total", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("vatted05Total", 0) | |
| } | |
| break | |
| case 29: | |
| //Total Venta 10 % | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("vatted10Total", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("vatted10Total", 0) | |
| } | |
| break | |
| case 30: | |
| //Total Venta Exentas | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("exemptTotal", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("exemptTotal", 0) | |
| } | |
| case 31: | |
| //Monto Total del IVA | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("vatTotal", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("vatTotal", 0) | |
| } | |
| break | |
| case 32: | |
| //Total Bruto | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("grossTotal", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("grossTotal", 0) | |
| } | |
| break | |
| case 33: | |
| //Total Descuento | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("discountTotal", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("discountTotal", 0) | |
| } | |
| break | |
| case 34: | |
| //Total Bonificacion | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("bonusTotal", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("bonusTotal", 0) | |
| } | |
| break | |
| case 35: | |
| //Total General | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("netTotal", Double.valueOf(headerFields[i]).doubleValue()) | |
| } else { | |
| headerMap.put("netTotal", 0) | |
| } | |
| break | |
| case 36: | |
| //User Code | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("salesmanCode", headerFields[i]) | |
| } else { | |
| headerMap.put("salesmanCode", "") | |
| } | |
| break | |
| case 37: | |
| //User Full Name | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("salesmanName", headerFields[i]) | |
| } else { | |
| headerMap.put("salesmanName", "") | |
| } | |
| break | |
| case 38: | |
| //Deposito | |
| if (!headerFields[i].equals("-1")) { | |
| String[] whereHouseStringArray = headerFields[i].split("\\."); | |
| if (whereHouseStringArray.size() > 1) { | |
| headerMap.put("wareHouseCode", whereHouseStringArray[0]); | |
| headerMap.put("wareHouseName", whereHouseStringArray[1]); | |
| } else { | |
| headerMap.put("wareHouseCode", headerFields[i]); | |
| headerMap.put("wareHouseName", headerFields[i]); | |
| } | |
| } else { | |
| headerMap.put("wareHouseCode", ""); | |
| headerMap.put("wareHouseName", ""); | |
| } | |
| break | |
| case 39: | |
| //Cash | |
| break | |
| case 40: | |
| //Credit | |
| break | |
| case 41: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("observation", headerFields[i]) | |
| } else { | |
| headerMap.put("observation", "") | |
| } | |
| break | |
| case 42: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("opt1", headerFields[i]) | |
| } else { | |
| headerMap.put("opt1", "") | |
| } | |
| break | |
| case 43: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("opt2", headerFields[i]) | |
| } else { | |
| headerMap.put("opt2", "") | |
| } | |
| break | |
| case 44: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("opt3", headerFields[i]) | |
| } else { | |
| headerMap.put("opt3", "") | |
| } | |
| break | |
| case 45: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("opt4", headerFields[i]) | |
| } else { | |
| headerMap.put("opt4", "") | |
| } | |
| break | |
| case 46: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("opt5", headerFields[i]) | |
| } else { | |
| headerMap.put("opt5", "") | |
| } | |
| break | |
| case 47: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("opt6", headerFields[i]) | |
| } else { | |
| headerMap.put("opt6", "") | |
| } | |
| break | |
| case 48: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("opt7", headerFields[i]) | |
| } else { | |
| headerMap.put("opt7", "") | |
| } | |
| break | |
| case 49: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("opt8", headerFields[i]) | |
| } else { | |
| headerMap.put("opt8", "") | |
| } | |
| break | |
| case 50: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("opt9", headerFields[i]) | |
| } else { | |
| headerMap.put("opt9", "") | |
| } | |
| break | |
| case 51: | |
| if (!headerFields[i].equals("-1")) { | |
| headerMap.put("opt10", headerFields[i]) | |
| } else { | |
| headerMap.put("opt10", "") | |
| } | |
| break | |
| case 52: | |
| //Primero se consulta si se recibe algun dato | |
| if (!headerFields[i].equals("-1")) { | |
| log.info("PRINT_TEXT: "+headerFields[i]); | |
| //Se valida si en la posicion 53 viene el texto correspondiente a la posible impresion | |
| if (headerFields[i].split("ŧ").size() > 1) { | |
| //Se cargan en el mapa el texto de impresion | |
| headerMap.put("printText", headerFields[i].split("ŧ")[3]) | |
| //Se consulta si vienen en la siguiente posicion --> i + 1, los datos de un formulario desbloqueable | |
| //En caso afirmativo se cargan los datos al mapa | |
| if ((headerFields.size() - 1) > 52 && (headerFields[i + 1].equals("true") || headerFields[i + 1].equals("false"))) { | |
| headerMap.put("unlocked", headerFields[i + 1]) | |
| headerMap.put("unlockCode", headerFields[i + 2]) | |
| } | |
| } else { | |
| //Sino, puede ser el mensaje de pedido bloqueado | |
| //En ese caso se consulta si lo que viene son los datos de un formulario desbloqueable y en ese caso | |
| //se cargan los datos al mapa | |
| if (headerFields[i].equals("true")) { | |
| headerMap.put("unlocked", headerFields[i]) | |
| headerMap.put("unlockCode", headerFields[i + 1]) | |
| } else if (headerFields[i].equals("false")) { | |
| headerMap.put("unlocked", headerFields[i]) | |
| headerMap.put("unlockCode", "") | |
| } else { | |
| headerMap.put("printText", "") | |
| } | |
| } | |
| } else { | |
| headerMap.put("printText", "") | |
| } | |
| break | |
| } | |
| } | |
| invoiceMapToReturn.put("header", headerMap); | |
| log.info("HEADER MAP TO RETURN: "+headerMap) | |
| // log.info("detailRows: "+detailRows) | |
| log.info("detailProducts: "+detailProducts) | |
| Map detailMap; | |
| for (int i = 0; i < detailProducts.length; i++) { | |
| detailMap = [:] | |
| // String detalle = messageBlocks[i + 1] | |
| String[] detailFields = detailProducts[i].split("¤") | |
| for (int j = 0; j < detailFields.length; j++) { | |
| switch (j) { | |
| case 0: | |
| detailMap.put("productCode", detailFields[j]) | |
| break | |
| case 1: | |
| detailMap.put("productName", detailFields[j]) | |
| break | |
| case 2: | |
| detailMap.put("productSelected", detailFields[j]) | |
| break | |
| case 3: | |
| // Porcentaje IVA | |
| if (!detailFields[j].equals("-1")) { | |
| try { | |
| detailMap.put("productVatRate", Double.valueOf(detailFields[j]).doubleValue()) | |
| } catch (NumberFormatException e) { | |
| log.error("Invalid product VAT rate value: " + detailFields[j], e) | |
| detailMap.put("productVatRate", 0) | |
| } | |
| } else { | |
| detailMap.put("productVatRate", 0) | |
| } | |
| break | |
| case 4: | |
| // seleccionar lista de precios | |
| if (!detailFields[j].equals("-1")) { | |
| // 1.Lista 1 2.Lista 2 | |
| if (detailFields[j].split("\\.").size() > 1) { | |
| detailMap.put("productPriceList", detailFields[j].split("\\.")[0]) | |
| detailMap.put("priceListName", detailFields[j].split("\\.")[1]) | |
| } else { | |
| detailMap.put("productPriceList", detailFields[j]) | |
| detailMap.put("priceListName", detailFields[j]) | |
| } | |
| } else { | |
| detailMap.put("productPriceList", "") | |
| detailMap.put("priceListName", "") | |
| } | |
| break | |
| case 5: | |
| // Precio del producto | |
| if (!detailFields[j].equals("-1")) { | |
| log.info("############################Precio del producto############################" + detailFields[j]); | |
| try { | |
| detailMap.put("unitPrice", Double.valueOf(detailFields[j]).doubleValue()) | |
| } catch (NumberFormatException e) { | |
| log.error("Invalid unit price value: " + detailFields[j], e) | |
| detailMap.put("unitPrice", 0) | |
| } | |
| } else { | |
| detailMap.put("unitPrice", 0) | |
| } | |
| break | |
| case 6: | |
| // Lote | |
| if (!detailFields[j].equals("-1")) { | |
| if (detailFields[j].split("\\.").size() > 1) { | |
| detailMap.put("productBatchCode", detailFields[j].split("\\.")[0]) | |
| detailMap.put("productBatchName", detailFields[j].split("\\.")[1]) | |
| } else { | |
| detailMap.put("productBatchCode", detailFields[j]) | |
| detailMap.put("productBatchName", detailFields[j]) | |
| } | |
| } else { | |
| detailMap.put("productBatchCode", "") | |
| detailMap.put("productBatchName", "") | |
| } | |
| break | |
| case 7: | |
| // Diseño | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("productDesign", detailFields[j]) | |
| } else { | |
| detailMap.put("productDesign", "") | |
| } | |
| break | |
| case 8: | |
| // Talle | |
| if (!detailFields[j].equals("-1")) { | |
| if (detailFields[j].split("\\.").size() > 1) { | |
| detailMap.put("productSizeCode", detailFields[j].split("\\.")[0]) | |
| detailMap.put("productSizeName", detailFields[j].split("\\.")[1]) | |
| } else { | |
| detailMap.put("productSizeCode", detailFields[j]) | |
| detailMap.put("productSizeName", detailFields[j]) | |
| } | |
| } else { | |
| detailMap.put("productSizeCode", "") | |
| detailMap.put("productSizeName", "") | |
| } | |
| break | |
| case 9: | |
| // Color | |
| if (!detailFields[j].equals("-1")) { | |
| if (detailFields[j].split("\\.").size() > 1) { | |
| detailMap.put("productColorCode", detailFields[j].split("\\.")[0]) | |
| detailMap.put("productColorName", detailFields[j].split("\\.")[1]) | |
| } else { | |
| detailMap.put("productColorCode", detailFields[j]) | |
| detailMap.put("productColorName", detailFields[j]) | |
| } | |
| } else { | |
| detailMap.put("productColorCode", "") | |
| detailMap.put("productColorName", "") | |
| } | |
| break | |
| case 10: | |
| // Unidad de medida | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("productUnit", detailFields[j]) | |
| } else { | |
| detailMap.put("productUnit", "") | |
| } | |
| break | |
| case 11: | |
| // Cantidad Equivalente | |
| break | |
| case 12: | |
| // VENCIMIENTO DE LOTE??? | |
| break | |
| case 13: | |
| // Existencia | |
| break | |
| case 14: | |
| // Cantidad a facturar | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("productQuantity", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("productQuantity", 0) | |
| } | |
| break | |
| case 15: | |
| // SubTotal BRUTO | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("grossAmount", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("grossAmount", 0) | |
| } | |
| break | |
| case 16: | |
| // Descuento Maximo???? | |
| break | |
| case 17: | |
| // PORCENTAJE DE DESCUENTO | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("discountRate", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("discountRate", 0) | |
| } | |
| break | |
| case 18: | |
| // Importe Descuento | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("discountAmount", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("discountAmount", 0) | |
| } | |
| break | |
| case 19: | |
| // Bonificacion Maxima | |
| break | |
| case 20: | |
| // CANTIDAD BONIFICADA | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("bonusQuantity", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("bonusQuantity", 0) | |
| } | |
| break | |
| case 21: | |
| // Cantidad Total = Cantidad a facturar + Cantidad Bonificada | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("totalQuantity", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("totalQuantity", 0) | |
| } | |
| break | |
| case 22: | |
| // Importe Bonificacion | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("bonusAmount", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("bonusAmount", 0) | |
| } | |
| break | |
| case 23: | |
| // Total Detalle Total Neto | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("netAmount", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("netAmount", 0) | |
| } | |
| break | |
| case 24: | |
| // IVA_5 | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("iva5", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("iva5", 0) | |
| } | |
| break | |
| case 25: | |
| // IVA_10 | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("iva10", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("iva10", 0) | |
| } | |
| break | |
| case 26: | |
| // EXENTA | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("exenta", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("exenta", 0) | |
| } | |
| break | |
| case 27: | |
| // Monto IVA_5 | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("vat05Amount", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("vat05Amount", 0) | |
| } | |
| break | |
| case 28: | |
| // Monto IVA_10 | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("vat10Amount", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("vat10Amount", 0) | |
| } | |
| break | |
| case 29: | |
| // Total IVA | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("vatAmount", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("vatAmount", 0) | |
| } | |
| break | |
| case 30: | |
| // Valor Venta 5 | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("vatted05Amount", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("vatted05Amount", 0) | |
| } | |
| break | |
| case 31: | |
| // Valor Venta 10 | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("vatted10Amount", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("vatted10Amount", 0) | |
| } | |
| break | |
| case 32: | |
| // Monto Venta Exentas | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("exemptAmount", Double.valueOf(detailFields[j]).doubleValue()) | |
| } else { | |
| detailMap.put("exemptAmount", 0) | |
| } | |
| break | |
| case 33: | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("opt1", detailFields[j]) | |
| } else { | |
| detailMap.put("opt1", "") | |
| } | |
| break | |
| case 34: | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("opt2", detailFields[j]) | |
| } else { | |
| detailMap.put("opt2", "") | |
| } | |
| break | |
| case 35: | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("opt3", detailFields[j]) | |
| } else { | |
| detailMap.put("opt3", "") | |
| } | |
| break | |
| case 36: | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("opt4", detailFields[j]) | |
| } else { | |
| detailMap.put("opt4", "") | |
| } | |
| break | |
| case 37: | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("opt5", detailFields[j]) | |
| } else { | |
| detailMap.put("opt5", "") | |
| } | |
| break | |
| case 38: | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("opt6", detailFields[j]) | |
| } else { | |
| detailMap.put("opt6", "") | |
| } | |
| break | |
| case 39: | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("opt7", detailFields[j]) | |
| } else { | |
| detailMap.put("opt7", "") | |
| } | |
| break | |
| case 40: | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("opt8", detailFields[j]) | |
| } else { | |
| detailMap.put("opt8", "") | |
| } | |
| break | |
| case 41: | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("opt9", detailFields[j]) | |
| } else { | |
| detailMap.put("opt9", "") | |
| } | |
| break | |
| case 42: | |
| if (!detailFields[j].equals("-1")) { | |
| detailMap.put("opt10", detailFields[j]) | |
| } else { | |
| detailMap.put("opt10", "") | |
| } | |
| break | |
| case 43: | |
| break | |
| log.info("LOOP DETAIL " + j) | |
| } | |
| } | |
| detailsList.add(detailMap); | |
| } | |
| Map paymentMap; | |
| for ( int p = 0; p < paymentMethods.length; p++ ){ | |
| switch(p){ | |
| case 0: | |
| paymentMap.put("value_amount", paymentMethods[p]) | |
| break | |
| case 1: | |
| paymentMap.put("payment", paymentMethods[p]) | |
| break | |
| case 2: | |
| paymentMap.put("bank", paymentMethods[p]) | |
| break | |
| case 3: | |
| paymentMap.put("document_number", paymentMethods[p]) | |
| break | |
| case 4: | |
| paymentMap.put("document_date", paymentMethods[p]) | |
| break | |
| case 5: | |
| paymentMap.put("document_expiration_date", paymentMethods[p]) | |
| break | |
| case 6: | |
| paymentMap.put("document_drawer", paymentMethods[p]) | |
| break | |
| case 7: | |
| paymentMap.put("payment_method_code", paymentMethods[p]) | |
| break | |
| } | |
| paymentList.add(paymentMap) | |
| } | |
| invoiceMapToReturn.put("details", detailsList); | |
| return invoiceMapToReturn | |
| } | |
| private long insertInvoiceHeader(User userInstance, HashMap headerMap, List wareHouseList, Timestamp dtTimeStamp, long eventId, Connection connPortal, PreparedStatement ps, ResultSet rs){ | |
| long invoiceId = 0 | |
| ps = connPortal.prepareStatement("Select nextval('invoice_seq')") | |
| rs = ps.executeQuery() | |
| if (rs.next()){ | |
| invoiceId = rs.getLong(1) | |
| } | |
| Group groupInstance = Group.createCriteria().get(){ | |
| and{ | |
| memberships{ | |
| eq("type",'MAIN') | |
| user{ eq("username", userInstance.username) } | |
| } | |
| } | |
| } | |
| String wareHouseCode = "" | |
| String wareHouseName = "" | |
| String warehousevalue = (String) headerMap.get("wareHouseCode") ; | |
| log.info("valor del deposito en el map: "+warehousevalue) | |
| String [] warehouseSplit = warehousevalue.split("\\.") ; | |
| if(wareHouseList.size() > 0){ | |
| log.info("de la lista") | |
| wareHouseCode = wareHouseList.get(1) | |
| wareHouseName = wareHouseList.get(2) | |
| }else{ | |
| wareHouseCode = headerMap.get('wareHouseCode'); | |
| wareHouseName = headerMap.get('wareHouseName'); | |
| log.info("WAREHOUSE: "+wareHouseCode+ " "+ wareHouseName) | |
| } | |
| String invoiceNumber = headerMap.get('number') | |
| String fiscalStampNumber = headerMap.get('fiscalStampNumber') | |
| String type = headerMap.get('type') | |
| String typeName = headerMap.get('typeName') | |
| String conditionCode = headerMap.get('conditionCode') | |
| String conditionName = headerMap.get('conditionName') | |
| String currencyCode = headerMap.get('currencyCode') | |
| String currencyName = headerMap.get('currencyName') | |
| String currencyExchange = headerMap.get('currencyExchange') | |
| String priceListCode = headerMap.get('priceListCode') | |
| String priceListName = headerMap.get('priceListName') | |
| String subjectCode = headerMap.get('subjectCode') | |
| String subjectName = headerMap.get('subjectName') | |
| String subjectCompanyAlias = headerMap.get('subjectCompanyAlias') | |
| String subjectFiscalNumber = headerMap.get('subjectFiscalNumber') | |
| String subjectPhoneNumber = headerMap.get('subjectPhone') | |
| String subjectAddress = headerMap.get('subjectAddress') | |
| String userCode = headerMap.get('salesmanCode') | |
| String userFullName = headerMap.get('salesmanName') | |
| String username = userInstance.username | |
| double totalAmount = headerMap.get('grossTotal') | |
| double discountRate = headerMap.get('discountRate') | |
| double totalDiscount = headerMap.get('discountTotal') | |
| double bonusQuantity = headerMap.get('bonusQuantity') | |
| double bonusTotal = headerMap.get('bonusTotal') | |
| double amountIva5 = headerMap.get('vat05Total') | |
| double amountIva10 = headerMap.get('vat10Total') | |
| double totalGeneral = headerMap.get('netTotal') | |
| double totalAmountIva5 = headerMap.get('vatted05Total') | |
| double totalAmountIva10 = headerMap.get('vatted10Total') | |
| double totalAmountIva = headerMap.get('vatTotal') | |
| double exemptTotal = headerMap.get('exemptTotal') | |
| String observation = headerMap.get('observation') | |
| String opt1 = headerMap.get('opt1') | |
| String opt2 = headerMap.get('opt2') | |
| String opt3 = headerMap.get('opt3') | |
| String opt4 = headerMap.get('opt4') | |
| String opt5 = headerMap.get('opt5') | |
| String opt6 = headerMap.get('opt6') | |
| String opt7 = headerMap.get('opt7') | |
| String opt8 = headerMap.get('opt8') | |
| String opt9 = headerMap.get('opt9') | |
| String opt10 = headerMap.get('opt10') | |
| String printText = "" | |
| if(headerMap.get('printText') != null){ | |
| printText = headerMap.get('printText') | |
| } | |
| String unlockedCode = "" | |
| if(headerMap.get('unlocked') != null){ | |
| unlockedCode = headerMap.get('unlockCode') | |
| } | |
| long hashUnlockCodeId = 0 | |
| StringBuilder unlockedCodeQueryString = new StringBuilder() | |
| unlockedCodeQueryString.append("SELECT id FROM hash_unlock_code WHERE subject_code = '$subjectCode' AND ") | |
| unlockedCodeQueryString.append(" code_generated_for_user_id = $userInstance.id AND unlock_code = '$unlockedCode' AND used = false") | |
| log.info("SELECT id FROM hash_unlock_code WHERE subject_code = '$subjectCode' AND code_generated_for_user_id = $userInstance.id AND unlock_code = '$unlockedCode' AND used = false") | |
| ps = connPortal.prepareStatement(unlockedCodeQueryString.toString()) | |
| rs = ps.executeQuery() | |
| if(rs.next()){ | |
| hashUnlockCodeId = rs.getInt(1) | |
| } | |
| log.info("hashUnlockCodeId: "+hashUnlockCodeId) | |
| String insertString ="INSERT INTO invoice (id, version, number, fiscal_stamp_number, cancelled,"+ | |
| "type, type_name, warehouse_code, warehouse_name, event_id, group_id, user_id,"+ | |
| "creation_date, delivery_date, status, condition_code, condition_name,"+ | |
| "currency_code, currency_name, currency_exchange, price_list_code,"+ | |
| "price_list_name, customer_code,customer_name, customer_company_alias,"+ | |
| "customer_fiscal_number, customer_phone, customer_address, company_alias,"+ | |
| "customer_vat, salesman_code, salesman_name, salesman_username, gross_total,"+ | |
| "discount_rate, discount_total, bonus_quantity,bonus_total, exempt_total,"+ | |
| "vatted05total, vatted10total, net_total, vat05total, vat10total, vat_total, observation,"+ | |
| "opt1, opt2, opt3, opt4, opt5, opt6, opt7, opt8, opt9, opt10, print_text, unlock_code, hash_unlock_code_id)"+ | |
| "VALUES($invoiceId,'0', '$invoiceNumber', '$fiscalStampNumber', false, '$type', '$typeName', "+ | |
| "'$wareHouseCode', '$wareHouseName', '$eventId', $groupInstance.id, $userInstance.id,"+ | |
| "'$dtTimeStamp', '$dtTimeStamp', 'N', '$conditionCode', '$conditionName', '$currencyCode', "+ | |
| "'$currencyName', '$currencyExchange', '$priceListCode', '$priceListName',"+ | |
| "'$subjectCode', '$subjectName', '$subjectCompanyAlias', '$subjectFiscalNumber', '$subjectPhoneNumber',"+ | |
| "'$subjectAddress', '$groupInstance.name', true, '$userCode', '$userFullName', '$username', "+ | |
| "$totalAmount, $discountRate, $totalDiscount, $bonusQuantity, $bonusTotal, $exemptTotal , $totalAmountIva5,"+ | |
| "$totalAmountIva10, $totalGeneral, $amountIva5, $amountIva10, $totalAmountIva, '$observation',"+ | |
| "'$opt1','$opt2','$opt3', '$opt4', '$opt5', '$opt6', '$opt7','$opt8','$opt9','$opt10', '$printText', '$unlockedCode', ?)" | |
| log.info("insertString: "+insertString); | |
| ps = connPortal.prepareStatement(insertString) | |
| if(hashUnlockCodeId != 0){ | |
| ps.setLong(1, hashUnlockCodeId) | |
| log.info("hashUnlockCodeId != 0") | |
| }else{ | |
| log.info("antes del setNull") | |
| log.info("ps.setNull(1, java.sql.Types.BIGINT)") | |
| ps.setNull(1, java.sql.Types.BIGINT) | |
| log.info("ps.setNull(1, java.sql.Types.BIGINT)") | |
| } | |
| ps.executeUpdate() | |
| if(hashUnlockCodeId != 0){ | |
| StringBuilder unlockedCodeUsedString = new StringBuilder() | |
| unlockedCodeUsedString.append("UPDATE hash_unlock_code SET used = true WHERE id = $hashUnlockCodeId") | |
| ps = connPortal.prepareStatement(unlockedCodeUsedString.toString()) | |
| ps.executeUpdate() | |
| } | |
| return invoiceId | |
| } | |
| private long insertInvoiceDetail(HashMap detailMap, double productQuantity, double bonusQuantity, int rowNumber, long invoiceId, Connection connPortal, PreparedStatement ps, ResultSet rs){ | |
| long invoiceDetailId = 0 | |
| ps = connPortal.prepareStatement("Select nextval('invoice_detail_seq')") | |
| rs = ps.executeQuery() | |
| if (rs.next()){ | |
| invoiceDetailId = rs.getLong(1) | |
| } | |
| String productCode = detailMap.get('productCode') | |
| String productDescription = detailMap.get('productName') | |
| String productSizeCode = detailMap.get('productSizeCode') | |
| String productSizeName = detailMap.get('productSizeName') | |
| String productColorCode = detailMap.get('productColorCode') | |
| String productColorName = detailMap.get('productColorName') | |
| String productBatchCode = detailMap.get('productBatchCode') | |
| String productBatchName = detailMap.get('productBatchName') | |
| String productDesign = detailMap.get('productDesign') | |
| double porcentIva = detailMap.get('productVatRate') | |
| String measureUnit = detailMap.get('productUnit') | |
| String priceListCode = detailMap.get('productPriceList') | |
| //double productQuantity = detailMap.get('productQuantity') | |
| Double productPrice = detailMap.get('unitPrice') != null ? Double.parseDouble(detailMap.get('unitPrice').toString()) : 0.0 | |
| double subTotal = detailMap.get('grossAmount') | |
| double discountRate = detailMap.get('discountRate') | |
| double importeDescuento = detailMap.get('discountAmount') | |
| //double bonusQuantity = detailMap.get('bonusQuantity') | |
| double importeBonificacion = detailMap.get('bonusAmount') | |
| double monto_iva5 = detailMap.get('vat05Amount') | |
| double monto_iva10 = detailMap.get('vat10Amount') | |
| double exemptAmount = detailMap.get('exemptAmount') | |
| double valorVenta5 = detailMap.get('vatted05Amount') | |
| double valorVenta10 = detailMap.get('vatted10Amount') | |
| double totalIva = detailMap.get('vatAmount') | |
| double totalDetalle = detailMap.get('netAmount') | |
| String opt1 = detailMap.get('opt1') | |
| String opt2 = detailMap.get('opt2') | |
| String opt3 = detailMap.get('opt3') | |
| String opt4 = detailMap.get('opt4') | |
| String opt5 = detailMap.get('opt5') | |
| String opt6 = detailMap.get('opt6') | |
| String opt7 = detailMap.get('opt7') | |
| String opt8 = detailMap.get('opt8') | |
| String opt9 = detailMap.get('opt9') | |
| String opt10 = detailMap.get('opt10') | |
| String insertString = "INSERT INTO invoice_detail (id, version, row_number, invoice_id, product_code, "+ | |
| "product_name, product_size_code, product_size_name, product_color_code, product_color_name, "+ | |
| "product_batch_code, product_batch_name, product_branch, product_design, product_vat_rate, "+ | |
| "product_unit, product_price_list, quantity, unit_price, gross_amount, discount_rate, discount_amount, "+ | |
| "bonus_quantity, bonus_amount, exempt_amount, vatted05amount, vatted10amount, vat05amount, "+ | |
| "vat10amount, vat_amount, net_amount, opt1, opt2, opt3, opt4, opt5, opt6, opt7, opt8, opt9, opt10) VALUES ('$invoiceDetailId','0', $rowNumber, '$invoiceId', "+ | |
| "'$productCode', '$productDescription', '$productSizeCode', '$productSizeName', "+ | |
| "'$productColorCode','$productColorName', '$productBatchCode', '$productBatchName', '',"+ | |
| "'$productDesign', $porcentIva,'$measureUnit', '$priceListCode', $productQuantity, $productPrice, "+ | |
| "$subTotal, $discountRate, $importeDescuento, $bonusQuantity, $importeBonificacion, "+ | |
| "$exemptAmount, $valorVenta5, $valorVenta10, $monto_iva5, $monto_iva10, $totalIva, $totalDetalle, "+ | |
| "'$opt1','$opt2','$opt3','$opt4','$opt5','$opt6','$opt7','$opt8','$opt9', '$opt10')" | |
| log.debug("DETALLE INVOICE insertString: "+insertString); | |
| ps = connPortal.prepareStatement(insertString) | |
| ps.executeUpdate() | |
| return invoiceDetailId | |
| } | |
| // MODIFICAR ESTE METODO PARA INSERTAR LOS MEDIOS DE PAGO EN EL PORTAL2 | |
| private long insertInvoicePayment(HashMap detailMap, double productQuantity, double bonusQuantity, int rowNumber, long invoiceId, Connection connPortal, PreparedStatement ps, ResultSet rs){ | |
| long invoicePaymentId = 0 | |
| ps = connPortal.prepareStatement("z") | |
| rs = ps.executeQuery() | |
| if (rs.next()){ | |
| invoicePaymentId = rs.getLong(1) | |
| } | |
| String productCode = detailMap.get('productCode') | |
| String productDescription = detailMap.get('productName') | |
| String productSizeCode = detailMap.get('productSizeCode') | |
| String productSizeName = detailMap.get('productSizeName') | |
| String productColorCode = detailMap.get('productColorCode') | |
| String productColorName = detailMap.get('productColorName') | |
| String productBatchCode = detailMap.get('productBatchCode') | |
| String productBatchName = detailMap.get('productBatchName') | |
| String productDesign = detailMap.get('productDesign') | |
| double porcentIva = detailMap.get('productVatRate') | |
| String measureUnit = detailMap.get('productUnit') | |
| String priceListCode = detailMap.get('productPriceList') | |
| //double productQuantity = detailMap.get('productQuantity') | |
| Double productPrice = detailMap.get('unitPrice') != null ? Double.parseDouble(detailMap.get('unitPrice').toString()) : 0.0 | |
| double subTotal = detailMap.get('grossAmount') | |
| double discountRate = detailMap.get('discountRate') | |
| double importeDescuento = detailMap.get('discountAmount') | |
| //double bonusQuantity = detailMap.get('bonusQuantity') | |
| double importeBonificacion = detailMap.get('bonusAmount') | |
| double monto_iva5 = detailMap.get('vat05Amount') | |
| double monto_iva10 = detailMap.get('vat10Amount') | |
| double exemptAmount = detailMap.get('exemptAmount') | |
| double valorVenta5 = detailMap.get('vatted05Amount') | |
| double valorVenta10 = detailMap.get('vatted10Amount') | |
| double totalIva = detailMap.get('vatAmount') | |
| double totalDetalle = detailMap.get('netAmount') | |
| String opt1 = detailMap.get('opt1') | |
| String opt2 = detailMap.get('opt2') | |
| String opt3 = detailMap.get('opt3') | |
| String opt4 = detailMap.get('opt4') | |
| String opt5 = detailMap.get('opt5') | |
| String opt6 = detailMap.get('opt6') | |
| String opt7 = detailMap.get('opt7') | |
| String opt8 = detailMap.get('opt8') | |
| String opt9 = detailMap.get('opt9') | |
| String opt10 = detailMap.get('opt10') | |
| String insertString = "INSERT INTO invoice_payment_detail (id, version, row_number, invoice_id, product_code, "+ | |
| "product_name, product_size_code, product_size_name, product_color_code, product_color_name, "+ | |
| "product_batch_code, product_batch_name, product_branch, product_design, product_vat_rate, "+ | |
| "product_unit, product_price_list, quantity, unit_price, gross_amount, discount_rate, discount_amount, "+ | |
| "bonus_quantity, bonus_amount, exempt_amount, vatted05amount, vatted10amount, vat05amount, "+ | |
| "vat10amount, vat_amount, net_amount, opt1, opt2, opt3, opt4, opt5, opt6, opt7, opt8, opt9, opt10) VALUES ('$invoiceDetailId','0', $rowNumber, '$invoiceId', "+ | |
| "'$productCode', '$productDescription', '$productSizeCode', '$productSizeName', "+ | |
| "'$productColorCode','$productColorName', '$productBatchCode', '$productBatchName', '',"+ | |
| "'$productDesign', $porcentIva,'$measureUnit', '$priceListCode', $productQuantity, $productPrice, "+ | |
| "$subTotal, $discountRate, $importeDescuento, $bonusQuantity, $importeBonificacion, "+ | |
| "$exemptAmount, $valorVenta5, $valorVenta10, $monto_iva5, $monto_iva10, $totalIva, $totalDetalle, "+ | |
| "'$opt1','$opt2','$opt3','$opt4','$opt5','$opt6','$opt7','$opt8','$opt9', '$opt10')" | |
| log.debug("MEDIOS DE PAGO INVOICE insertString: "+insertString); | |
| ps = connPortal.prepareStatement(insertString) | |
| ps.executeUpdate() | |
| return invoiceDetailId | |
| } | |
| private long updateBook(Connection connPortal, PreparedStatement ps, User userInstance, String fiscalStampNumber, def dtTimeStamp, String boca, String sucursal){ | |
| String bookUpdate = "UPDATE book set last_value = last_value + 1, last_value_date = '$dtTimeStamp' where user_id = "+userInstance.id+" and fiscal_stamp_number = '"+fiscalStampNumber+"' and branch_office = '"+sucursal+"' and sale_point = '"+boca+"'" | |
| log.info(bookUpdate); | |
| ps = connPortal.prepareStatement(bookUpdate) | |
| ps.executeUpdate() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment