Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
Use una matriz de números de factura para crear objetos de factura dentro de los cuales cada número de factura de la matriz inicial sirve como propiedad de identificación

Creación de un script en el script de Google Apps.

  • Obtengo valores de una hoja de datos de factura con varias líneas por factura para contabilizar los elementos de línea.

  • Mi progreso hasta ahora ha sido extraer números de factura individuales de la columna (cada número de factura aparece como muchos elementos de línea tiene la factura individual).

  • La matriz Facturas de hoy tiene este aspecto: [35033817, 35033818, 35033819, 35033820, 35033821]

  • Ahora, necesito una forma de crear un objeto para cada uno de estos números de factura que tenga diferentes propiedades (como fecha de factura y nombre de cliente, etc.). El número de factura inicial como en la matriz debe asignarse como propiedad 'id' al nuevo objeto de factura.

  • Necesito ayuda para usar objetos en javascript.

  • Si requiere información adicional, por favor hágamelo saber.

A continuación se muestra una captura de pantalla de una versión simplificada de mi hoja de pedido:

Este es un recorte de mi hoja de pedido. Antes y despues de las columnas mostradas hay muchas mas con mas detalles pero las jerarquias de informacion ya estan en la imagen

ingrese la descripción de la imagen aquí

A continuación se muestra el código que tengo hasta ahora:

 const orderSheet = SpreadsheetApp.openById('SPREADSHEETID').getSheetByName('SHEETNAME'); const invoiceTemplate = DriveApp.getFileById('DOCUMENTID'); const tempFolder = DriveApp.getFolderById('FOLDERID'); const invoiceData = orderSheet.getRange(4,7, orderSheet.getLastRow() - 1, 57).getDisplayValues().filter(function (rows){ return rows[0] === 'INVOICED'}); const invDataRepo = SpreadsheetApp.openById('SPREADSHEETID2'); var timestamp = new Date(); function printBulkInvoices() { logLineItems (); var todaysInvoices = uniqueInvIDs (); todaysInvoices.sort(); todaysInvoices.map(String); //fetchInvData (todaysInvoices); Logger.log (todaysInvoices) } function fetchInvData (invoiceIDs) { let invoices = { } Logger.log(invoices) invoiceIDs.forEach } function fetchLineItems (invoiceDataArray) { } // send array of todays unique invoice numbers (later all inv data?) to invdata sheet and log them function logTodaysInvoices (invIDArr){ invIDArr.forEach invDataRepo.getSheetByName('invdata').getRange(invDataRepo.getSheetByName('invdata').getLastRow()+1,1,invIDArr.length,1).setValue(invIDArr); } // return an array of unique invoice ids from todays invoice data function uniqueInvIDs (){ let singleArray = invoiceData.map(row => row[5]); let unique = [...new Set(singleArray)]; return unique; } //log incoicedata to invdatarepo-sheet 'lineitems' function logLineItems (){ invDataRepo.getSheetByName('lineitems').getRange(invDataRepo.getSheetByName('lineitems').getLastRow()+1,2,invoiceData.length,invoiceData[0].length).setValues(invoiceData); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Es difícil decir exactamente lo que necesita ya que no podemos ver su Hoja de datos de la factura. Pero aquí hay algo que podría darle un comienzo:

 let iobj = {idA:[]}; [35033817, 35033818, 35033819, 35033820, 35033821].forEach((id => { if(!iobj.hasOwnProperty(id)) { iobj[id]={date: invoiceDate, name: customName, items:[]}; iobj.idA.push(id);//I find it handy to have an array of object properties to loop through when I wish to reorganize the data after it's all collected } else { iobj[id].items.push({item info properties});//I am guessing here that you may wish to addition additional information about the items which are on the current invoice } });
  • Objeto JavaScript

Para dar seguimiento a tu pregunta:

Su ciclo para recopilar datos de objetos comenzaría a verse así:

 function getInvoiceData() { const ss = SpreadsheetApp.getActive(); const ish = ss.getSheetByName('Invoice Data'); const isr = 2; const hA = ish.getRange(1, 1, 1, ish.getLastColumn()).getValues()[0]; let idx = {};//object return head index into row array based on header title which in this case I assume invoice number is labeled 'Invoicenumber' hA.forEach((h, i) => {idx[h] = i}); const vs = ish.getRange(isr, 1, ish.getLastRow() - isr + 1, ish.getLastColumn()).getValues(); let iobj = { idA: [] }; vs.forEach(r => { if (!iobj.hasOwnProperty(r[idx['invoicenumber']])) { iobj[r[idx['invoicenumber']]] = { date: r[idx['invoicedate']], name: r[idx['customername']], items: [] }; iobj.idA.push(r[idx['invoicenumber']]); } else { iobj[r[idx['invoicenumber']]].items.push({ iteminfoproperties:'' }); } }); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!