2025-05-31 19:26:02 +02:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using Google.Apis.Sheets.v4;
|
|
|
|
|
|
using Google.Apis.Sheets.v4.Data;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2025-06-02 18:53:25 +02:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2025-05-31 19:26:02 +02:00
|
|
|
|
using DiunaBI.Core.Models;
|
2025-06-06 22:15:23 +02:00
|
|
|
|
using DiunaBI.Core.Database.Context;
|
2025-05-31 19:26:02 +02:00
|
|
|
|
using DiunaBI.Core.Services;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiunaBI.Plugins.Morska.Processors;
|
|
|
|
|
|
|
2025-06-02 16:54:33 +02:00
|
|
|
|
public class T4R2Processor : MorskaBaseProcessor
|
|
|
|
|
|
{
|
|
|
|
|
|
public override string ProcessorType => "T4.R2";
|
|
|
|
|
|
|
|
|
|
|
|
private readonly AppDbContext _db;
|
|
|
|
|
|
private readonly SpreadsheetsResource.ValuesResource _googleSheetValues;
|
2025-06-02 18:53:25 +02:00
|
|
|
|
private readonly ILogger<T4R2Processor> _logger;
|
|
|
|
|
|
|
2025-06-02 16:54:33 +02:00
|
|
|
|
public T4R2Processor(
|
2025-06-02 18:53:25 +02:00
|
|
|
|
AppDbContext db,
|
|
|
|
|
|
SpreadsheetsResource.ValuesResource googleSheetValues,
|
|
|
|
|
|
ILogger<T4R2Processor> logger)
|
2025-06-02 16:54:33 +02:00
|
|
|
|
{
|
|
|
|
|
|
_db = db;
|
|
|
|
|
|
_googleSheetValues = googleSheetValues;
|
2025-06-02 18:53:25 +02:00
|
|
|
|
_logger = logger;
|
2025-06-02 16:54:33 +02:00
|
|
|
|
}
|
2025-06-02 18:53:25 +02:00
|
|
|
|
|
2025-06-02 16:54:33 +02:00
|
|
|
|
public override void Process(Layer processWorker)
|
2025-05-31 19:26:02 +02:00
|
|
|
|
{
|
2025-06-02 18:53:25 +02:00
|
|
|
|
_logger.LogInformation("T4R2: Starting processing for {ProcessWorkerName} ({ProcessWorkerId})",
|
|
|
|
|
|
processWorker.Name, processWorker.Id);
|
|
|
|
|
|
|
2025-05-31 19:26:02 +02:00
|
|
|
|
var year = int.Parse(processWorker.Records?.SingleOrDefault(x => x.Code == "Year")?.Desc1!);
|
|
|
|
|
|
var sources = processWorker.Records?.Where(x => x.Code == "Source").ToList();
|
|
|
|
|
|
if (sources!.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("Source record not found");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var layerName = processWorker.Records?.SingleOrDefault(x => x.Code == "LayerName")?.Desc1;
|
|
|
|
|
|
if (layerName == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("LayerName record not found");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var processedLayer = _db.Layers
|
2025-05-31 19:26:02 +02:00
|
|
|
|
.Where(x => x.ParentId == processWorker.Id
|
|
|
|
|
|
&& !x.IsDeleted && !x.IsCancelled)
|
|
|
|
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
var isNew = false;
|
|
|
|
|
|
if (processedLayer == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
isNew = true;
|
|
|
|
|
|
processedLayer = new Layer
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
|
Type = LayerType.Processed,
|
|
|
|
|
|
ParentId = processWorker.Id,
|
2025-06-02 16:54:33 +02:00
|
|
|
|
Number = _db.Layers.Count() + 1
|
2025-05-31 19:26:02 +02:00
|
|
|
|
};
|
|
|
|
|
|
processedLayer.Name = $"L{processedLayer.Number}-{layerName}";
|
|
|
|
|
|
processedLayer.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
|
|
|
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
|
|
|
|
processedLayer.CreatedAt = DateTime.UtcNow;
|
|
|
|
|
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
processedLayer.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
|
|
|
|
processedLayer.ModifiedAt = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newRecords = new List<Record>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var source in sources)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rawSourceCodes = processWorker.Records?.SingleOrDefault(x => x.Code == $"Codes-{source.Desc1}")
|
|
|
|
|
|
?.Desc1;
|
|
|
|
|
|
var sourceCodes = new List<int>();
|
|
|
|
|
|
if (rawSourceCodes != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
sourceCodes = ProcessHelper.ParseCodes(rawSourceCodes);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<string> lastSourceCodes = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (var month = 1; month <= 12; month++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((year == DateTime.UtcNow.Year && month <= DateTime.UtcNow.Month) || year < DateTime.UtcNow.Year)
|
|
|
|
|
|
{
|
|
|
|
|
|
var monthCopy = month;
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var dataSource = _db.Layers.Where(x =>
|
2025-05-31 19:26:02 +02:00
|
|
|
|
x.Type == LayerType.Processed &&
|
|
|
|
|
|
!x.IsDeleted && !x.IsCancelled &&
|
|
|
|
|
|
x.Name != null && x.Name.Contains($"{year}/{monthCopy:D2}-{source.Desc1}-T")
|
|
|
|
|
|
)
|
|
|
|
|
|
.Include(x => x.Records)
|
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
if (dataSource != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastSourceCodes = dataSource.Records!.Select(x => x.Code!).ToList();
|
|
|
|
|
|
var news = dataSource.Records!
|
|
|
|
|
|
.Where(x => sourceCodes.Count <= 0 || sourceCodes.Contains(int.Parse(x.Code!)))
|
|
|
|
|
|
.Select(x =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var newRecord = new Record
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
|
Code = $"{x.Code}{month:D2}",
|
|
|
|
|
|
CreatedAt = DateTime.UtcNow,
|
|
|
|
|
|
ModifiedAt = DateTime.UtcNow,
|
|
|
|
|
|
Value1 = source.Desc1 != "FK2" ? x.Value32 : x.Value1,
|
|
|
|
|
|
Desc1 = x.Desc1
|
|
|
|
|
|
};
|
|
|
|
|
|
return newRecord;
|
|
|
|
|
|
}
|
|
|
|
|
|
).ToList();
|
|
|
|
|
|
newRecords.AddRange(news);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-06-02 18:53:25 +02:00
|
|
|
|
_logger.LogWarning("T4R2: Data source {DataSource} not found. Process: {ProcessName} ({ProcessId})",
|
|
|
|
|
|
$"{year}/{month:D2}-{source.Desc1}-T3", processWorker.Name, processWorker.Id);
|
2025-05-31 19:26:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//0 values for future months
|
|
|
|
|
|
if (source.Desc1 == "FK2" || lastSourceCodes.Count <= 0) continue;
|
|
|
|
|
|
var news = lastSourceCodes
|
|
|
|
|
|
.Where(x => sourceCodes.Contains(int.Parse(x)))
|
|
|
|
|
|
.Select(x =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var newRecord = new Record
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
|
Code = $"{x}{month:D2}",
|
|
|
|
|
|
CreatedAt = DateTime.UtcNow,
|
|
|
|
|
|
ModifiedAt = DateTime.UtcNow,
|
|
|
|
|
|
Value1 = 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
return newRecord;
|
|
|
|
|
|
}
|
|
|
|
|
|
).ToList();
|
|
|
|
|
|
newRecords.AddRange(news);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// year summary
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var dataSourceSum = _db.Layers.Where(x =>
|
2025-05-31 19:26:02 +02:00
|
|
|
|
x.Type == LayerType.Processed &&
|
|
|
|
|
|
!x.IsDeleted && !x.IsCancelled &&
|
|
|
|
|
|
x.Name != null && x.Name.Contains($"{year}/13-{source.Desc1}-T")
|
|
|
|
|
|
)
|
|
|
|
|
|
.Include(x => x.Records)
|
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
if (dataSourceSum != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var news = dataSourceSum.Records!
|
|
|
|
|
|
.Where(x => sourceCodes.Count <= 0 || sourceCodes.Contains(int.Parse(x.Code!)))
|
|
|
|
|
|
.Select(x =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var newRecord = new Record
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
|
Code = $"{x.Code}13",
|
|
|
|
|
|
CreatedAt = DateTime.UtcNow,
|
|
|
|
|
|
ModifiedAt = DateTime.UtcNow,
|
|
|
|
|
|
Value1 = x.Value32
|
|
|
|
|
|
};
|
|
|
|
|
|
return newRecord;
|
|
|
|
|
|
}
|
|
|
|
|
|
).ToList();
|
|
|
|
|
|
newRecords.AddRange(news);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-06-02 18:53:25 +02:00
|
|
|
|
_logger.LogWarning("T4R2: Data source {DataSource} not found. Process: {ProcessName} ({ProcessId})",
|
|
|
|
|
|
$"{year}/13-{source.Desc1}-T3", processWorker.Name, processWorker.Id);
|
2025-05-31 19:26:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isNew)
|
|
|
|
|
|
{
|
2025-06-02 16:54:33 +02:00
|
|
|
|
_db.Layers.Add(processedLayer);
|
2025-05-31 19:26:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-06-02 16:54:33 +02:00
|
|
|
|
_db.Layers.Update(processedLayer);
|
2025-05-31 19:26:02 +02:00
|
|
|
|
}
|
2025-06-02 18:53:25 +02:00
|
|
|
|
|
|
|
|
|
|
SaveRecords(processedLayer.Id, newRecords);
|
2025-06-02 16:54:33 +02:00
|
|
|
|
_db.SaveChanges();
|
2025-05-31 19:26:02 +02:00
|
|
|
|
|
|
|
|
|
|
var reportSheetName = processWorker.Records?.SingleOrDefault(x => x.Code == "GoogleSheetName")?.Desc1;
|
|
|
|
|
|
if (reportSheetName == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("GoogleSheetName record not found");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var invoicesSheetName = processWorker.Records?.SingleOrDefault(x => x.Code == "GoogleSheetName-Invoices")?.Desc1;
|
|
|
|
|
|
if (invoicesSheetName == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("GoogleSheetName-Invoices record not found");
|
|
|
|
|
|
}
|
2025-06-02 18:53:25 +02:00
|
|
|
|
|
2025-05-31 19:26:02 +02:00
|
|
|
|
UpdateReport(processedLayer.Id, reportSheetName, invoicesSheetName);
|
2025-06-02 18:53:25 +02:00
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("T4R2: Successfully completed processing for {ProcessWorkerName} ({ProcessWorkerId})",
|
|
|
|
|
|
processWorker.Name, processWorker.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SaveRecords(Guid layerId, ICollection<Record> records)
|
|
|
|
|
|
{
|
|
|
|
|
|
var toDelete = _db.Records.Where(x => x.LayerId == layerId).ToList();
|
|
|
|
|
|
if (toDelete.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_db.Records.RemoveRange(toDelete);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var record in records)
|
|
|
|
|
|
{
|
|
|
|
|
|
record.CreatedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
|
|
|
|
record.CreatedAt = DateTime.UtcNow;
|
|
|
|
|
|
record.ModifiedById = Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D");
|
|
|
|
|
|
record.ModifiedAt = DateTime.UtcNow;
|
|
|
|
|
|
record.LayerId = layerId;
|
|
|
|
|
|
_db.Records.Add(record);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_logger.LogDebug("T4R2: Saved {RecordCount} records for layer {LayerId}", records.Count, layerId);
|
2025-05-31 19:26:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateReport(Guid sourceId, string reportSheetName, string invoicesSheetName)
|
|
|
|
|
|
{
|
|
|
|
|
|
const string sheetId = "1FsUmk_YRIeeGzFCX9tuUJCaLyRtjutX2ZGAEU1DMfJQ";
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var request = _googleSheetValues.Get(sheetId, "C4:Z4");
|
2025-05-31 19:26:02 +02:00
|
|
|
|
var response = request.Execute();
|
|
|
|
|
|
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var r2 = _db.Layers
|
2025-05-31 19:26:02 +02:00
|
|
|
|
.Where(x => x.Id == sourceId && !x.IsDeleted && !x.IsCancelled)
|
|
|
|
|
|
.Include(x => x.Records)
|
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
|
|
const int startRow = 6;
|
|
|
|
|
|
|
|
|
|
|
|
var codesRow = response.Values[0];
|
|
|
|
|
|
for (var i = 1; i <= 12; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var values = new List<object>();
|
|
|
|
|
|
var month = i < 10 ? $"0{i}" : i.ToString();
|
|
|
|
|
|
var row = (startRow + i).ToString();
|
|
|
|
|
|
foreach (string code in codesRow)
|
|
|
|
|
|
{
|
|
|
|
|
|
var record = r2!.Records?.SingleOrDefault(x => x.Code == $"{code}{month}");
|
|
|
|
|
|
if (record != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
values.Add(record.Value1!.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
values.Add("0");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
var valueRange = new ValueRange
|
|
|
|
|
|
{
|
|
|
|
|
|
Values = new List<IList<object>> { values }
|
|
|
|
|
|
};
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var update = _googleSheetValues.Update(valueRange, sheetId, $"{reportSheetName}!C{row}:XZ{row}");
|
2025-05-31 19:26:02 +02:00
|
|
|
|
update.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
|
|
|
|
update.Execute();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// sum
|
|
|
|
|
|
var valuesSum = new List<object>();
|
|
|
|
|
|
var emptyRow = new List<object>();
|
|
|
|
|
|
var rowEmpty = (startRow + 13).ToString();
|
|
|
|
|
|
var rowSum = (startRow + 14).ToString();
|
|
|
|
|
|
foreach (string code in codesRow)
|
|
|
|
|
|
{
|
|
|
|
|
|
var record = r2!.Records?.SingleOrDefault(x => x.Code == $"{code}13");
|
|
|
|
|
|
emptyRow.Add("");
|
|
|
|
|
|
if (record != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
valuesSum.Add(record.Value1!.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
valuesSum.Add("0");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// insert empty row before sum
|
|
|
|
|
|
var valueRangeEmpty = new ValueRange
|
|
|
|
|
|
{
|
|
|
|
|
|
Values = new List<IList<object>> { emptyRow }
|
|
|
|
|
|
};
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var updateEmpty = _googleSheetValues.Update(valueRangeEmpty, sheetId, $"{reportSheetName}!C{rowEmpty}:XZ{rowEmpty}");
|
2025-05-31 19:26:02 +02:00
|
|
|
|
updateEmpty.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
|
|
|
|
updateEmpty.Execute();
|
|
|
|
|
|
|
|
|
|
|
|
var valueRangeSum = new ValueRange
|
|
|
|
|
|
{
|
|
|
|
|
|
Values = new List<IList<object>> { valuesSum }
|
|
|
|
|
|
};
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var updateSum = _googleSheetValues.Update(valueRangeSum, sheetId, $"{reportSheetName}!C{rowSum}:XZ{rowSum}");
|
2025-05-31 19:26:02 +02:00
|
|
|
|
updateSum.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
|
|
|
|
updateSum.Execute();
|
|
|
|
|
|
|
|
|
|
|
|
// update time
|
|
|
|
|
|
var timeUtc = new List<object>
|
|
|
|
|
|
{
|
|
|
|
|
|
r2!.ModifiedAt.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
|
|
|
|
|
};
|
|
|
|
|
|
var valueRangeUtcTime = new ValueRange
|
|
|
|
|
|
{
|
|
|
|
|
|
Values = new List<IList<object>> { timeUtc }
|
|
|
|
|
|
};
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var updateTimeUtc = _googleSheetValues.Update(valueRangeUtcTime, sheetId, $"{reportSheetName}!G1");
|
2025-05-31 19:26:02 +02:00
|
|
|
|
updateTimeUtc.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
|
|
|
|
updateTimeUtc.Execute();
|
|
|
|
|
|
|
|
|
|
|
|
var warsawTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
|
|
|
|
|
|
var warsawTime = TimeZoneInfo.ConvertTimeFromUtc(r2.ModifiedAt.ToUniversalTime(), warsawTimeZone);
|
|
|
|
|
|
var timeWarsaw = new List<object>
|
|
|
|
|
|
{
|
|
|
|
|
|
warsawTime.ToString("dd.MM.yyyy HH:mm:ss", CultureInfo.GetCultureInfo("pl-PL"))
|
|
|
|
|
|
};
|
|
|
|
|
|
var valueRangeWarsawTime = new ValueRange
|
|
|
|
|
|
{
|
|
|
|
|
|
Values = new List<IList<object>> { timeWarsaw }
|
|
|
|
|
|
};
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var updateTimeWarsaw = _googleSheetValues.Update(valueRangeWarsawTime, sheetId, $"{reportSheetName}!G2");
|
2025-05-31 19:26:02 +02:00
|
|
|
|
updateTimeWarsaw.ValueInputOption = SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
|
|
|
|
updateTimeWarsaw.Execute();
|
|
|
|
|
|
|
|
|
|
|
|
//invoices
|
|
|
|
|
|
|
|
|
|
|
|
var invoices = r2.Records!.Where(x => x.Code!.Length == 12)
|
|
|
|
|
|
.OrderByDescending(x => x.Code);
|
|
|
|
|
|
|
|
|
|
|
|
var invoicesValues = new List<IList<object>>();
|
|
|
|
|
|
var cleanUpValues = new List<IList<object>>();
|
|
|
|
|
|
foreach (var invoice in invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
var invoiceDate =
|
|
|
|
|
|
DateTime.ParseExact(invoice.Code!.Substring(0, 8), "yyyyMMdd", CultureInfo.InvariantCulture)
|
|
|
|
|
|
.ToString("dd.MM.yyyy", CultureInfo.GetCultureInfo("pl-PL"));
|
|
|
|
|
|
var invoiceRow = new List<object>
|
|
|
|
|
|
{
|
|
|
|
|
|
invoiceDate,
|
|
|
|
|
|
"",
|
|
|
|
|
|
invoice.Desc1!,
|
|
|
|
|
|
invoice.Value1!
|
|
|
|
|
|
};
|
|
|
|
|
|
invoicesValues.Add(invoiceRow);
|
|
|
|
|
|
|
|
|
|
|
|
var cleanupRow = new List<object>
|
|
|
|
|
|
{
|
|
|
|
|
|
"", "", "", ""
|
|
|
|
|
|
};
|
|
|
|
|
|
cleanUpValues.Add(cleanupRow);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cleanupValueRange = new ValueRange { Values = cleanUpValues };
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var cleanupInvoices = _googleSheetValues.Update(cleanupValueRange, sheetId, $"{invoicesSheetName}!A6:E");
|
2025-05-31 19:26:02 +02:00
|
|
|
|
cleanupInvoices.ValueInputOption =
|
|
|
|
|
|
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
|
|
|
|
cleanupInvoices.Execute();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var invoicesValueRange = new ValueRange { Values = invoicesValues };
|
2025-06-02 16:54:33 +02:00
|
|
|
|
var updateInvoices = _googleSheetValues.Update(invoicesValueRange, sheetId, $"{invoicesSheetName}!A6:E");
|
2025-05-31 19:26:02 +02:00
|
|
|
|
updateInvoices.ValueInputOption =
|
|
|
|
|
|
SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.USERENTERED;
|
|
|
|
|
|
updateInvoices.Execute();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|