Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
[Back] Export divider | StockChange | IsArchived | Split ProductGetCo…
Browse files Browse the repository at this point in the history
…mboList - [Front] stale-while-revalidate
  • Loading branch information
Aloento committed Feb 8, 2024
1 parent 544be09 commit 9bbce2a
Show file tree
Hide file tree
Showing 12 changed files with 1,093 additions and 80 deletions.
54 changes: 38 additions & 16 deletions TSystems.LoveOTC/AdminHub/Order/Export.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal partial class AdminHub {
* <remarks>
* @author Aloento
* @since 1.2.0
* @version 1.0.0
* @version 1.1.0
* </remarks>
*/
public async IAsyncEnumerable<byte[]> ExportOrder() {
Expand All @@ -57,11 +57,33 @@ public async IAsyncEnumerable<byte[]> ExportOrder() {
};
sheets.Append(sheet);

var cells = new List<Cell>(7) {
new() {
DataType = CellValues.String,
CellValue = new(nameof(LoveOTC))
}
};

for (var i = 0; i < 5; i++)
cells.Add(new() {
DataType = CellValues.String,
CellValue = new(" ")
});

cells.Add(new() {
DataType = CellValues.String,
CellValue = new($"This order sheet was exported on {DateTime.Now:yyyy-MM-dd HH:mm}")
});

var timestamp = new Row();
sheetData.AppendChild(timestamp);
timestamp.Append(new Cell {
timestamp.Append(cells);

var divider = new Row();
sheetData.AppendChild(divider);
divider.Append(new Cell {
DataType = CellValues.String,
CellValue = new($"This order sheet was exported on {DateTime.Now:yyyy-MM-dd HH:mm}")
CellValue = new(" ")
});

var headerRow = new Row();
Expand Down Expand Up @@ -106,16 +128,16 @@ public async IAsyncEnumerable<byte[]> ExportOrder() {
var combo = record.Combo;
var currId = order.OrderId;

var data = new List<OpenXmlElement>(12) {
new Cell {
var data = new List<Cell>(12) {
new() {
DataType = CellValues.Number,
CellValue = new((decimal)currId)
},
new Cell {
new() {
DataType = CellValues.String,
CellValue = new(order.CreateAt.ToString("yyyy-MM-dd HH:mm"))
},
new Cell {
new() {
DataType = CellValues.SharedString,
CellValue = new(shared(combo.Product.Name))
}
Expand All @@ -133,15 +155,15 @@ public async IAsyncEnumerable<byte[]> ExportOrder() {
.ToString();

data.AddRange([
new Cell {
new() {
DataType = CellValues.String,
CellValue = new(types)
},
new Cell {
new() {
DataType = CellValues.Number,
CellValue = new((decimal)record.Quantity)
},
new Cell {
new() {
DataType = CellValues.SharedString,
CellValue = new(shared(order.Status.ToString()))
}
Expand All @@ -158,19 +180,19 @@ public async IAsyncEnumerable<byte[]> ExportOrder() {
});

data.AddRange([
new Cell {
new() {
DataType = CellValues.SharedString,
CellValue = new(shared(user.Name))
},
new Cell {
new() {
DataType = CellValues.SharedString,
CellValue = new(shared(user.EMail))
},
new Cell {
new() {
DataType = CellValues.SharedString,
CellValue = new(shared(user.Phone))
},
new Cell {
new() {
DataType = CellValues.SharedString,
CellValue = new(shared(user.Address))
}
Expand All @@ -192,12 +214,12 @@ public async IAsyncEnumerable<byte[]> ExportOrder() {
})
.ToString();

data.Add(new Cell {
data.Add(new() {
DataType = CellValues.String,
CellValue = new(cmts)
});
} else
data.Add(new Cell {
data.Add(new() {
DataType = CellValues.String,
CellValue = new("-")
});
Expand Down
8 changes: 7 additions & 1 deletion TSystems.LoveOTC/AdminHub/Order/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ await this.Db.Comments.AddAsync(new() {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 1.1.0
* @version 1.2.0
* </remarks>
*/
public async Task<bool> OrderPostClose(uint orderId, string reason) {
Expand All @@ -56,8 +56,14 @@ public async Task<bool> OrderPostClose(uint orderId, string reason) {
.Where(x => x.OrderId == orderId)
.Where(x => x.Status != OrderStatus.Cancelled)
.Where(x => x.Status != OrderStatus.Finished)
.Include(x => x.OrderCombos)
.ThenInclude(x => x.Combo)
.SingleAsync();

if (order.Status is OrderStatus.Pending or OrderStatus.Processing)
foreach (var oc in order.OrderCombos)
oc.Combo.Stock += oc.Quantity;

order.Status = OrderStatus.Finished;
await this.Db.Comments.AddAsync(new() {
Content = "[Admin Close] " + reason,
Expand Down
6 changes: 3 additions & 3 deletions TSystems.LoveOTC/Hub/Order/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public async Task<bool> OrderPostCancel(uint orderId, string reason) {
.ThenInclude(x => x.Combo)
.SingleAsync();

foreach (var oc in order.OrderCombos)
oc.Combo.Stock += oc.Quantity;

order.Status = order.Status == OrderStatus.Shipping
? OrderStatus.Returning
: OrderStatus.Cancelled;
Expand All @@ -136,9 +139,6 @@ await this.Db.Comments.AddAsync(new() {
Order = order
});

foreach (var oc in order.OrderCombos)
oc.Combo.Stock += oc.Quantity;

return await this.Db.SaveChangesAsync() > 0;
}

Expand Down
30 changes: 30 additions & 0 deletions TSystems.LoveOTC/Hub/Product/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal partial class ShopHub {

return await this.Db.Products
.Where(x => x.ProductId == key)
.Where(x => x.IsArchived != true)
.Select(x => new {
x.Name,
Category = x.Category!.Name,
Expand All @@ -45,6 +46,7 @@ internal partial class ShopHub {

return await this.Db.Products
.Where(x => x.ProductId == key)
.Where(x => x.IsArchived != true)
.Select(x => new {
x.Description,
x.Version
Expand Down Expand Up @@ -89,6 +91,7 @@ internal partial class ShopHub {

return await this.Db.Types
.Where(x => x.TypeId == key)
.Where(x => x.IsArchived != true)
.Select(x => new {
x.Name,
x.VariantId,
Expand All @@ -114,11 +117,38 @@ internal partial class ShopHub {

return await this.Db.Variants
.Where(x => x.VariantId == key)
.Where(x => x.IsArchived != true)
.Select(x => new {
x.Name,
x.ProductId,
x.Version
})
.SingleOrDefaultAsync();
}

/**
* <remarks>
* @author Aloento
* @since 1.3.0
* @version 0.1.0
* </remarks>
*/
public async Task<dynamic?> ComboEntity(uint key, uint? version) {
if (version is not null) {
var noChange = await this.Db.Combos
.AnyAsync(x => x.ComboId == key && x.Version == version);

if (noChange) return true;
}

return await this.Db.Combos
.Where(x => x.ComboId == key)
.Where(x => x.IsArchived != true)
.Select(x => new {
x.Stock,
Types = x.Types.Select(t => t.TypeId).ToArray(),
x.Version
})
.SingleOrDefaultAsync();
}
}
13 changes: 5 additions & 8 deletions TSystems.LoveOTC/Hub/Product/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ internal partial class ShopHub {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 1.0.0
* @version 1.1.0
* </remarks>
*/
public async Task<dynamic[]> ProductGetComboList(uint prodId) =>
await this.Db.Combos
public Task<uint[]> ProductGetComboList(uint prodId) =>
this.Db.Combos
.Where(x => x.ProductId == prodId)
.Select(x => new {
x.ComboId,
x.Stock,
Types = x.Types.Select(t => t.TypeId).ToArray()
})
.Where(x => x.IsArchived != true)
.Select(x => x.ComboId)
.ToArrayAsync();

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@microsoft/signalr-protocol-msgpack": "^8.0.0",
"ahooks": "^3.7.10",
"dayjs": "^1.11.10",
"dexie": "^3.2.4",
"dexie": "^3.2.5",
"dexie-react-hooks": "^1.1.7",
"lexical": "0.10.0",
"lodash-es": "^4.17.21",
Expand All @@ -56,6 +56,6 @@
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react-swc": "^3.6.0",
"typescript": "^5.3.3",
"vite": "^5.0.12"
"vite": "^5.1.0"
}
}
Loading

0 comments on commit 9bbce2a

Please sign in to comment.